source: osm/applications/editors/josm/i18n/convpreset.pl@ 25195

Last change on this file since 25195 was 25155, checked in by stoecker, 14 years ago

update translation issues

File size: 4.9 KB
RevLine 
[11529]1#! /usr/bin/perl -w
2
3# Written by Dirk Stöcker <openstreetmap@dstoecker.de>
4# Public domain, no rights reserved.
5
6use strict;
7
8my $item = "";
9my $group;
[24764]10my $combo_n;
11my @combo_values;
12my $combo_idx;
[25155]13my $result = 0;
[11529]14my $comment = 0;
15
16# This is a simple conversion and in no way a complete XML parser
17# but it works with a default Perl installation
18
[13392]19# Print a header to write valid Java code. No line break,
20# so that the input and output line numbers will match.
21print "class trans_preset { void tr(String s){} void f() {";
22
[11529]23while(my $line = <>)
24{
25 chomp($line);
26 if($line =~ /<item\s+name=(".*?")/)
27 {
[17969]28 my $val = $1;
29 $item = $group ? "$group$val" : $val;
[11529]30 $item =~ s/""/\//;
[17969]31 if($line =~ /name_context=(".*?")/)
32 {
[23091]33 print "/* item $item */ trc($1, $val);\n";
[17969]34 }
35 else
36 {
[23091]37 print "/* item $item */ tr($val);\n";
[17969]38 }
[11529]39 }
[17969]40 elsif($line =~ /<group.*\s+name=(".*?")/)
[11529]41 {
[17973]42 my $gr = $1;
43 $group = $group ? "$group$gr" : $gr;
[17969]44 $group =~ s/\"\"/\//;
45 if($line =~ /name_context=(".*?")/)
46 {
[23091]47 print "/* group $group */ trc($1,$gr);\n";
[17969]48 }
49 else
50 {
[23091]51 print "/* group $group */ tr($gr);\n";
[17969]52 }
[11529]53 }
[17969]54 elsif($line =~ /<label.*\s+text=" "/)
[11529]55 {
56 print "/* item $item empty label */\n";
57 }
[17969]58 elsif($line =~ /<label.*\s+text=(".*?")/)
[11529]59 {
[17969]60 my $text = $1;
61 if($line =~ /text_context=(".*?")/)
62 {
[23091]63 print "/* item $item label $text */ trc($1,$text);\n";
[17969]64 }
65 else
66 {
[23091]67 print "/* item $item label $text */ tr($text);\n";
[17969]68 }
[11529]69 }
[17969]70 elsif($line =~ /<text.*\s+text=(".*?")/)
[11529]71 {
72 my $n = $1;
[17969]73 if($line =~ /text_context=(".*?")/)
74 {
[23091]75 print "/* item $item text $n */ trc($1,$n);\n";
[17969]76 }
77 else
78 {
[23091]79 print "/* item $item text $n */ tr($n);\n";
[17969]80 }
[11529]81 }
[17969]82 elsif($line =~ /<check.*\s+text=(".*?")/)
[11529]83 {
84 my $n = $1;
[17969]85 if($line =~ /text_context=(".*?")/)
86 {
[23091]87 print "/* item $item check $n */ trc($1,$n);\n";
[17969]88 }
89 else
90 {
[23091]91 print "/* item $item check $n */ tr($n);\n";
[17969]92 }
[11529]93 }
[17969]94 elsif($line =~ /<role.*\s+text=(".*?")/)
[13469]95 {
96 my $n = $1;
[17969]97 if($line =~ /text_context=(".*?")/)
98 {
[23091]99 print "/* item $item role $n */ trc($1,$n);\n";
[17969]100 }
101 else
102 {
[23091]103 print "/* item $item role $n */ tr($n);\n";
[17969]104 }
[13469]105 }
[11529]106 # first handle display values
[25155]107 elsif($line =~ /<(combo|multiselect).*\s+text=(".*?").*\s+display_values="(.*?)"/)
[11529]108 {
[25155]109 my ($type,$n,$vals) = ($1,$2,$3);
110 my $sp = ($type eq "combo" ? ",":";");
[24764]111 $combo_n = $n;
112 $combo_idx = 0;
[17969]113 my $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
114 if($line =~ /text_context=(".*?")/)
115 {
[25155]116 print "/* item $item $type $n */ trc($1,$n);";
[17969]117 }
118 else
119 {
[25155]120 print "/* item $item $type $n */ tr($n);";
[17969]121 }
[25155]122 $vals =~ s/\\$sp/\x91/g;
123 @combo_values = split $sp,$vals;
[24764]124 for (my $i=0; $i<@combo_values; ++$i) {
[25155]125 $combo_values[$i] =~ s/\x91/$sp/g;
[24764]126 next if $combo_values[$i] =~ /^[0-9-]+$/; # search for non-numbers
[25155]127 print "/* item $item $type $n display value */" . ($vctx ? " trc($vctx, \"$combo_values[$i]\");" : " tr(\"$combo_values[$i]\");");
[11529]128 }
129 print "\n";
130 }
[25155]131 elsif($line =~ /<(combo|multiselect).*\s+text=(".*?").*\s+values="(.*?)"/)
[11529]132 {
[25155]133 my ($type,$n,$vals) = ($1,$2,$3);
134 my $sp = ($type eq "combo" ? ",":";");
[24764]135 $combo_n = $n;
136 $combo_idx = 0;
[17969]137 my $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
138 if($line =~ /text_context=(".*?")/)
139 {
[25155]140 print "/* item $item $type $n */ trc($1,$n);";
[17969]141 }
142 else
143 {
[25155]144 print "/* item $item $type $n */ tr($n);";
[17969]145 }
[25155]146 @combo_values = split $sp,$vals;
[24764]147 foreach my $val (@combo_values)
[11529]148 {
149 next if $val =~ /^[0-9-]+$/; # search for non-numbers
[25155]150 print "/* item $item $type $n display value */" . ($vctx ? " trc($vctx, \"$val\");" : " tr(\"$val\");");
[11529]151 }
152 print "\n";
153 }
[24903]154 elsif(!$comment && $line =~ /<short_description>(.*?)<\/short_description>/)
[24764]155 {
156 my $n = $1;
157 print "/* item $item combo $combo_n item \"$combo_values[$combo_idx]\" short description */ tr(\"$n\");\n";
158 $combo_idx++;
159 }
[11529]160 elsif($line =~ /<\/group>/)
161 {
[17969]162 $group = 0 if !($group =~ s/(.*\/).*?$//);
[11529]163 print "\n";
164 }
165 elsif($line =~ /<\/item>/)
166 {
167 $item = "";
168 print "\n";
169 }
[24764]170 elsif($line =~ /<\/combo/)
171 {
172 $combo_n = "";
173 $combo_idx = 0;
174 }
[13469]175 elsif(!$line)
176 {
177 print "\n";
178 }
[11529]179 elsif($line =~ /^\s*$/
[13140]180 || $line =~ /<separator *\/>/
181 || $line =~ /<space *\/>/
182 || $line =~ /<\/?optional>/
[11529]183 || $line =~ /<key/
[25155]184 || $line =~ /<presets/
185 || $line =~ /<\/presets/
[13469]186 || $line =~ /roles/
187 || $line =~ /href=/
[11529]188 || $line =~ /<!--/
[25155]189 || $line =~ /<\?xml/
[11529]190 || $line =~ /-->/
191 || $comment)
192 {
[13469]193 print "// $line\n";
[11529]194 }
195 else
196 {
197 print "/* unparsed line $line */\n";
[25155]198 $result = 20
[11529]199 }
200
201 # note, these two must be in this order ore oneliners aren't handled
202 $comment = 1 if($line =~ /<!--/);
203 $comment = 0 if($line =~ /-->/);
204}
[13392]205
206print "}}\n";
[25155]207return $result if $result;
Note: See TracBrowser for help on using the repository browser.