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

Last change on this file since 21626 was 17973, checked in by stoecker, 15 years ago

fixed typos

File size: 4.0 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;
10my $comment = 0;
11
12# This is a simple conversion and in no way a complete XML parser
13# but it works with a default Perl installation
14
[13392]15# Print a header to write valid Java code. No line break,
16# so that the input and output line numbers will match.
17print "class trans_preset { void tr(String s){} void f() {";
18
[11529]19while(my $line = <>)
20{
21 chomp($line);
22 if($line =~ /<item\s+name=(".*?")/)
23 {
[17969]24 my $val = $1;
25 $item = $group ? "$group$val" : $val;
[11529]26 $item =~ s/""/\//;
[17969]27 if($line =~ /name_context=(".*?")/)
28 {
29 print "trc($1, $val); /* item $item */\n";
30 }
31 else
32 {
33 print "tr($val); /* item $item */\n";
34 }
[11529]35 }
[17969]36 elsif($line =~ /<group.*\s+name=(".*?")/)
[11529]37 {
[17973]38 my $gr = $1;
39 $group = $group ? "$group$gr" : $gr;
[17969]40 $group =~ s/\"\"/\//;
41 if($line =~ /name_context=(".*?")/)
42 {
[17973]43 print "trc($1,$gr); /* group $group */\n";
[17969]44 }
45 else
46 {
[17973]47 print "tr($gr); /* group $group */\n";
[17969]48 }
[11529]49 }
[17969]50 elsif($line =~ /<label.*\s+text=" "/)
[11529]51 {
52 print "/* item $item empty label */\n";
53 }
[17969]54 elsif($line =~ /<label.*\s+text=(".*?")/)
[11529]55 {
[17969]56 my $text = $1;
57 if($line =~ /text_context=(".*?")/)
58 {
59 print "trc($1,$text); /* item $item label $text */\n";
60 }
61 else
62 {
63 print "tr($text); /* item $item label $text */\n";
64 }
[11529]65 }
[17969]66 elsif($line =~ /<text.*\s+text=(".*?")/)
[11529]67 {
68 my $n = $1;
[17969]69 if($line =~ /text_context=(".*?")/)
70 {
71 print "trc($1,$n); /* item $item text $n */\n";
72 }
73 else
74 {
75 print "tr($n); /* item $item text $n */\n";
76 }
[11529]77 }
[17969]78 elsif($line =~ /<check.*\s+text=(".*?")/)
[11529]79 {
80 my $n = $1;
[17969]81 if($line =~ /text_context=(".*?")/)
82 {
83 print "trc($1,$n); /* item $item check $n */\n";
84 }
85 else
86 {
87 print "tr($n); /* item $item check $n */\n";
88 }
[11529]89 }
[17969]90 elsif($line =~ /<role.*\s+text=(".*?")/)
[13469]91 {
92 my $n = $1;
[17969]93 if($line =~ /text_context=(".*?")/)
94 {
95 print "trc($1,$n); /* item $item role $n */\n";
96 }
97 else
98 {
99 print "tr($n); /* item $item role $n */\n";
100 }
[13469]101 }
[11529]102 # first handle display values
[17969]103 elsif($line =~ /<combo.*\s+text=(".*?").*\s+display_values="(.*?)"/)
[11529]104 {
105 my ($n,$vals) = ($1,$2);
[17969]106 my $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
107 if($line =~ /text_context=(".*?")/)
108 {
109 print "trc($1,$n); /* item $item combo $n */";
110 }
111 else
112 {
113 print "tr($n); /* item $item combo $n */";
114 }
[11529]115 foreach my $val (split ",",$vals)
116 {
117 next if $val =~ /^[0-9-]+$/; # search for non-numbers
[17969]118 print $vctx ? " trc($vctx, \"$val\");" : " tr(\"$val\");";
[11529]119 }
120 print "\n";
121 }
[17969]122 elsif($line =~ /<combo.*\s+text=(".*?").*\s+values="(.*?)"/)
[11529]123 {
124 my ($n,$vals) = ($1,$2);
[17969]125 my $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
126 if($line =~ /text_context=(".*?")/)
127 {
128 print "trc($1,$n); /* item $item combo $n */";
129 }
130 else
131 {
132 print "tr($n); /* item $item combo $n */";
133 }
[11529]134 foreach my $val (split ",",$vals)
135 {
136 next if $val =~ /^[0-9-]+$/; # search for non-numbers
[17969]137 print $vctx ? " trc($vctx, \"$val\");" : " tr(\"$val\");";
[11529]138 }
139 print "\n";
140 }
141 elsif($line =~ /<\/group>/)
142 {
[17969]143 $group = 0 if !($group =~ s/(.*\/).*?$//);
[11529]144 print "\n";
145 }
146 elsif($line =~ /<\/item>/)
147 {
148 $item = "";
149 print "\n";
150 }
[13469]151 elsif(!$line)
152 {
153 print "\n";
154 }
[11529]155 elsif($line =~ /^\s*$/
[13140]156 || $line =~ /<separator *\/>/
157 || $line =~ /<space *\/>/
158 || $line =~ /<\/?optional>/
[11529]159 || $line =~ /<key/
160 || $line =~ /annotations/
[13469]161 || $line =~ /roles/
162 || $line =~ /href=/
[11529]163 || $line =~ /<!--/
164 || $line =~ /-->/
165 || $comment)
166 {
[13469]167 print "// $line\n";
[11529]168 }
169 else
170 {
171 print "/* unparsed line $line */\n";
[13140]172# print STDERR "Unparsed line $line\n";
[11529]173 }
174
175 # note, these two must be in this order ore oneliners aren't handled
176 $comment = 1 if($line =~ /<!--/);
177 $comment = 0 if($line =~ /-->/);
178}
[13392]179
180print "}}\n";
Note: See TracBrowser for help on using the repository browser.