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

Last change on this file since 31140 was 31139, checked in by stoecker, 10 years ago

add be language

File size: 5.5 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;
[28250]11my $combo_type;
[25155]12my $result = 0;
[11529]13my $comment = 0;
[28250]14my $vctx;
[11529]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
[26180]23sub fix($)
24{
25 my ($val) = @_;
26 $val =~ s/'/''/g;
[31076]27 $val =~ s/&lt;/</g;
28 $val =~ s/&gt;/>/g;
29 $val =~ s/&amp;/&/g;
[26180]30 return $val;
31}
32
[29933]33my $linenr = 0;
[11529]34while(my $line = <>)
35{
[29933]36 ++$linenr;
[11529]37 chomp($line);
[29943]38 print "tr(\"\"); ";
[11529]39 if($line =~ /<item\s+name=(".*?")/)
40 {
[26180]41 my $val = fix($1);
[17969]42 $item = $group ? "$group$val" : $val;
[11529]43 $item =~ s/""/\//;
[17969]44 if($line =~ /name_context=(".*?")/)
45 {
[23091]46 print "/* item $item */ trc($1, $val);\n";
[17969]47 }
48 else
49 {
[23091]50 print "/* item $item */ tr($val);\n";
[17969]51 }
[11529]52 }
[17969]53 elsif($line =~ /<group.*\s+name=(".*?")/)
[11529]54 {
[26180]55 my $gr = fix($1);
[17973]56 $group = $group ? "$group$gr" : $gr;
[17969]57 $group =~ s/\"\"/\//;
58 if($line =~ /name_context=(".*?")/)
59 {
[23091]60 print "/* group $group */ trc($1,$gr);\n";
[17969]61 }
62 else
63 {
[23091]64 print "/* group $group */ tr($gr);\n";
[17969]65 }
[11529]66 }
[17969]67 elsif($line =~ /<label.*\s+text=" "/)
[11529]68 {
69 print "/* item $item empty label */\n";
70 }
[17969]71 elsif($line =~ /<label.*\s+text=(".*?")/)
[11529]72 {
[26180]73 my $text = fix($1);
[17969]74 if($line =~ /text_context=(".*?")/)
75 {
[23091]76 print "/* item $item label $text */ trc($1,$text);\n";
[17969]77 }
78 else
79 {
[23091]80 print "/* item $item label $text */ tr($text);\n";
[17969]81 }
[11529]82 }
[17969]83 elsif($line =~ /<text.*\s+text=(".*?")/)
[11529]84 {
[26180]85 my $n = fix($1);
[17969]86 if($line =~ /text_context=(".*?")/)
87 {
[23091]88 print "/* item $item text $n */ trc($1,$n);\n";
[17969]89 }
90 else
91 {
[23091]92 print "/* item $item text $n */ tr($n);\n";
[17969]93 }
[11529]94 }
[17969]95 elsif($line =~ /<check.*\s+text=(".*?")/)
[11529]96 {
[26180]97 my $n = fix($1);
[17969]98 if($line =~ /text_context=(".*?")/)
99 {
[23091]100 print "/* item $item check $n */ trc($1,$n);\n";
[17969]101 }
102 else
103 {
[23091]104 print "/* item $item check $n */ tr($n);\n";
[17969]105 }
[11529]106 }
[17969]107 elsif($line =~ /<role.*\s+text=(".*?")/)
[13469]108 {
[26180]109 my $n = fix($1);
[17969]110 if($line =~ /text_context=(".*?")/)
111 {
[23091]112 print "/* item $item role $n */ trc($1,$n);\n";
[17969]113 }
114 else
115 {
[23091]116 print "/* item $item role $n */ tr($n);\n";
[17969]117 }
[13469]118 }
[29933]119 elsif($line =~ /<optional.*\s+text=(".*?")/)
120 {
121 my $n = fix($1);
122 if($line =~ /text_context=(".*?")/)
123 {
124 print "/* item $item optional $n */ trc($1,$n);\n";
125 }
126 else
127 {
128 print "/* item $item optional $n */ tr($n);\n";
129 }
130 }
[28250]131 elsif($line =~ /<(combo|multiselect).*\s+text=(".*?")/)
[11529]132 {
[28250]133 my ($type,$n) = ($1,fix($2));
134 $combo_n = $n;
135 $combo_type = $type;
136 $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
137 # text
138 my $tctx = ($line =~ /text_context=(".*?")/) ? $1 : undef;
139 print "/* item $item $type $n */" . ($tctx ? " trc($tctx, $n);" : " tr($n);");
140 # display_values / values
[30038]141 my $sp = ($line =~ /delimiter="(.*?)"/) ? $1 : ($type eq "combo" ? ",":";");
[31111]142 my $vals = ($line =~ / display_values="(.*?)"/) ? $1 : ($line =~ /values="(.*?)"/) ? $1 : undef;
[28250]143 if($vals)
[17969]144 {
[30038]145 my @combo_values = split "\Q$sp\E" ,$vals;
[28250]146 foreach my $val (@combo_values)
147 {
148 next if $val =~ /^[0-9-]+$/; # search for non-numbers
149 $val = fix($val);
150 print "/* item $item $type $n display value */" . ($vctx ? " trc($vctx, \"$val\");" : " tr(\"$val\");");
151 }
[17969]152 }
[11529]153 print "\n";
154 }
[28250]155 elsif(!$comment && $line =~ /<list_entry/)
[11529]156 {
[28250]157 my $vctxi = ($line =~ /value_context=(".*?")/) ? $1 : $vctx;
158 my $value = ($line =~ /value=(".*?")/) ? $1 : undef;
159 if($line =~ /display_value=(".*?")/)
[17969]160 {
[28250]161 my $val = fix($1);
[28252]162 print "/* item $item $combo_type $combo_n entry $value display value */" . ($vctxi ? " trc($vctxi, $val);" : " tr($val);");
[17969]163 }
164 else
165 {
[28250]166 my $val = fix($value);
[28252]167 print "/* item $item $combo_type $combo_n entry $value display value */" . ($vctxi ? " trc($vctxi, $val);" : " tr($val);");
[17969]168 }
[28250]169 if($line =~ /short_description=(".*?")/)
[11529]170 {
[28250]171 my $val = fix($1);
[28252]172 print "/* item $item $combo_type $combo_n entry $value short description */ tr($val);";
[11529]173 }
[28252]174 print "\n";
[11529]175 }
176 elsif($line =~ /<\/group>/)
177 {
[17969]178 $group = 0 if !($group =~ s/(.*\/).*?$//);
[11529]179 print "\n";
180 }
181 elsif($line =~ /<\/item>/)
182 {
183 $item = "";
184 print "\n";
185 }
[31111]186 elsif($line =~ /<\/(combo|multiselect)/)
[24764]187 {
188 $combo_n = "";
[29999]189 print "\n";
[24764]190 }
[13469]191 elsif(!$line)
192 {
193 print "\n";
194 }
[11529]195 elsif($line =~ /^\s*$/
[13140]196 || $line =~ /<separator *\/>/
197 || $line =~ /<space *\/>/
198 || $line =~ /<\/?optional>/
[11529]199 || $line =~ /<key/
[25155]200 || $line =~ /<presets/
[29933]201 || $line =~ /<checkgroup/
202 || $line =~ /<\/checkgroup/
[25155]203 || $line =~ /<\/presets/
[13469]204 || $line =~ /roles/
205 || $line =~ /href=/
[11529]206 || $line =~ /<!--/
[25155]207 || $line =~ /<\?xml/
[11529]208 || $line =~ /-->/
[30159]209 || $line =~ /<\/?chunk/
210 || $line =~ /<reference/
211 || $line =~ /<preset_link/
[31139]212 || $line =~ /<item_separator\/>/
[11529]213 || $comment)
214 {
[31111]215 $line =~ s/[ \t]+((?:short)?description) *= *"([^"]+)/*\/ \/* $1 *\/ tr("$2"); \/*/g;
216 print "/* $line */\n";
[11529]217 }
218 else
219 {
220 print "/* unparsed line $line */\n";
[29933]221 print STDERR "/* unparsed line $linenr $line */\n";
[25155]222 $result = 20
[11529]223 }
224
225 # note, these two must be in this order ore oneliners aren't handled
226 $comment = 1 if($line =~ /<!--/);
227 $comment = 0 if($line =~ /-->/);
228}
[13392]229
230print "}}\n";
[29208]231exit($result) if $result;
Note: See TracBrowser for help on using the repository browser.