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

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

update translation issues

File size: 4.9 KB
Line 
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;
10my $combo_n;
11my @combo_values;
12my $combo_idx;
13my $result = 0;
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
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
23while(my $line = <>)
24{
25 chomp($line);
26 if($line =~ /<item\s+name=(".*?")/)
27 {
28 my $val = $1;
29 $item = $group ? "$group$val" : $val;
30 $item =~ s/""/\//;
31 if($line =~ /name_context=(".*?")/)
32 {
33 print "/* item $item */ trc($1, $val);\n";
34 }
35 else
36 {
37 print "/* item $item */ tr($val);\n";
38 }
39 }
40 elsif($line =~ /<group.*\s+name=(".*?")/)
41 {
42 my $gr = $1;
43 $group = $group ? "$group$gr" : $gr;
44 $group =~ s/\"\"/\//;
45 if($line =~ /name_context=(".*?")/)
46 {
47 print "/* group $group */ trc($1,$gr);\n";
48 }
49 else
50 {
51 print "/* group $group */ tr($gr);\n";
52 }
53 }
54 elsif($line =~ /<label.*\s+text=" "/)
55 {
56 print "/* item $item empty label */\n";
57 }
58 elsif($line =~ /<label.*\s+text=(".*?")/)
59 {
60 my $text = $1;
61 if($line =~ /text_context=(".*?")/)
62 {
63 print "/* item $item label $text */ trc($1,$text);\n";
64 }
65 else
66 {
67 print "/* item $item label $text */ tr($text);\n";
68 }
69 }
70 elsif($line =~ /<text.*\s+text=(".*?")/)
71 {
72 my $n = $1;
73 if($line =~ /text_context=(".*?")/)
74 {
75 print "/* item $item text $n */ trc($1,$n);\n";
76 }
77 else
78 {
79 print "/* item $item text $n */ tr($n);\n";
80 }
81 }
82 elsif($line =~ /<check.*\s+text=(".*?")/)
83 {
84 my $n = $1;
85 if($line =~ /text_context=(".*?")/)
86 {
87 print "/* item $item check $n */ trc($1,$n);\n";
88 }
89 else
90 {
91 print "/* item $item check $n */ tr($n);\n";
92 }
93 }
94 elsif($line =~ /<role.*\s+text=(".*?")/)
95 {
96 my $n = $1;
97 if($line =~ /text_context=(".*?")/)
98 {
99 print "/* item $item role $n */ trc($1,$n);\n";
100 }
101 else
102 {
103 print "/* item $item role $n */ tr($n);\n";
104 }
105 }
106 # first handle display values
107 elsif($line =~ /<(combo|multiselect).*\s+text=(".*?").*\s+display_values="(.*?)"/)
108 {
109 my ($type,$n,$vals) = ($1,$2,$3);
110 my $sp = ($type eq "combo" ? ",":";");
111 $combo_n = $n;
112 $combo_idx = 0;
113 my $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
114 if($line =~ /text_context=(".*?")/)
115 {
116 print "/* item $item $type $n */ trc($1,$n);";
117 }
118 else
119 {
120 print "/* item $item $type $n */ tr($n);";
121 }
122 $vals =~ s/\\$sp/\x91/g;
123 @combo_values = split $sp,$vals;
124 for (my $i=0; $i<@combo_values; ++$i) {
125 $combo_values[$i] =~ s/\x91/$sp/g;
126 next if $combo_values[$i] =~ /^[0-9-]+$/; # search for non-numbers
127 print "/* item $item $type $n display value */" . ($vctx ? " trc($vctx, \"$combo_values[$i]\");" : " tr(\"$combo_values[$i]\");");
128 }
129 print "\n";
130 }
131 elsif($line =~ /<(combo|multiselect).*\s+text=(".*?").*\s+values="(.*?)"/)
132 {
133 my ($type,$n,$vals) = ($1,$2,$3);
134 my $sp = ($type eq "combo" ? ",":";");
135 $combo_n = $n;
136 $combo_idx = 0;
137 my $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
138 if($line =~ /text_context=(".*?")/)
139 {
140 print "/* item $item $type $n */ trc($1,$n);";
141 }
142 else
143 {
144 print "/* item $item $type $n */ tr($n);";
145 }
146 @combo_values = split $sp,$vals;
147 foreach my $val (@combo_values)
148 {
149 next if $val =~ /^[0-9-]+$/; # search for non-numbers
150 print "/* item $item $type $n display value */" . ($vctx ? " trc($vctx, \"$val\");" : " tr(\"$val\");");
151 }
152 print "\n";
153 }
154 elsif(!$comment && $line =~ /<short_description>(.*?)<\/short_description>/)
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 }
160 elsif($line =~ /<\/group>/)
161 {
162 $group = 0 if !($group =~ s/(.*\/).*?$//);
163 print "\n";
164 }
165 elsif($line =~ /<\/item>/)
166 {
167 $item = "";
168 print "\n";
169 }
170 elsif($line =~ /<\/combo/)
171 {
172 $combo_n = "";
173 $combo_idx = 0;
174 }
175 elsif(!$line)
176 {
177 print "\n";
178 }
179 elsif($line =~ /^\s*$/
180 || $line =~ /<separator *\/>/
181 || $line =~ /<space *\/>/
182 || $line =~ /<\/?optional>/
183 || $line =~ /<key/
184 || $line =~ /<presets/
185 || $line =~ /<\/presets/
186 || $line =~ /roles/
187 || $line =~ /href=/
188 || $line =~ /<!--/
189 || $line =~ /<\?xml/
190 || $line =~ /-->/
191 || $comment)
192 {
193 print "// $line\n";
194 }
195 else
196 {
197 print "/* unparsed line $line */\n";
198 $result = 20
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}
205
206print "}}\n";
207return $result if $result;
Note: See TracBrowser for help on using the repository browser.