Changeset 31111 in osm for applications/editors/josm/i18n/i18n.pl
- Timestamp:
- 2015-05-02T15:15:29+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/i18n/i18n.pl
r31088 r31111 2 2 3 3 use utf8; 4 use strict; 4 5 use open qw/:std :encoding(utf8)/; 5 6 use Term::ReadKey; … … 7 8 8 9 my $waswarn = 0; 9 my $maxcount = 0;10 10 my $lang_pattern = '([a-z]{2}_[A-Z]{2}|[a-z]{2,3}|[a-z]{2}\@[a-z]+)'; 11 11 my $lang_pattern_file = '([a-z]{2}_[A-Z]{2}|[a-z]{2,3}|[a-z]{2}-[a-z]+)'; … … 20 20 } 21 21 22 sub loadfiles($@) 22 sub loadpot($) 23 { 24 my ($file) = @_; 25 my %all = (); 26 my %keys = (); 27 die "Could not open file $file." if(!open FILE,"<:utf8",$file); 28 my %postate = (last => "", type => ""); 29 my $linenum = 0; 30 print "Reading file $file\n"; 31 while(<FILE>) 32 { 33 ++$linenum; 34 my $fn = "$file:$linenum"; 35 chomp; 36 if($_ =~ /^#/ || !$_) 37 { 38 checkpo(\%postate, \%all, "pot", "line $linenum in $file", \%keys, 1, undef); 39 $postate{fuzzy} = 1 if ($_ =~ /fuzzy/); 40 } 41 elsif($_ =~ /^"(.*)"$/) {$postate{last} .= $1;} 42 elsif($_ =~ /^(msg.+) "(.*)"$/) 43 { 44 my ($n, $d) = ($1, $2); 45 my $new = !${postate}{fuzzy} && (($n eq "msgid" && $postate{type} ne "msgctxt") || ($n eq "msgctxt")); 46 checkpo(\%postate, \%all, "pot", "line $linenum in $file", \%keys, $new, undef); 47 $postate{last} = $d; 48 $postate{type} = $n; 49 $postate{src} = $fn if $new; 50 } 51 else 52 { 53 die "Strange line $linenum in $file: $_."; 54 } 55 } 56 checkpo(\%postate, \%all, "pot", "line $linenum in $file", \%keys, 1, undef); 57 close(FILE); 58 return \%all; 59 } 60 61 sub loadfiles($$@) 23 62 { 24 63 my $desc; 25 my $all; 26 my ($lang,@files) = @_; 64 my %all = (); 65 my %keys = (); 66 my ($lang,$use,@files) = @_; 27 67 foreach my $file (@files) 28 68 { 29 69 die "Could not open file $file." if(!open FILE,"<:utf8",$file); 30 my $linenum = 0; 31 32 my $cnt = -1; # don't count translators info 70 33 71 if($file =~ /\/$lang_pattern\.po$/) 34 72 { … … 45 83 if($_ =~ /^#/ || !$_) 46 84 { 47 checkpo(\%postate, \%all, $l, "line $linenum in $file", $keys, 1);85 checkpo(\%postate, \%all, $l, "line $linenum in $file", \%keys, 1, $use); 48 86 $postate{fuzzy} = 1 if ($_ =~ /fuzzy/); 49 87 } … … 52 90 { 53 91 my ($n, $d) = ($1, $2); 54 ++$cnt if $n eq "msgid";55 92 my $new = !${postate}{fuzzy} && (($n eq "msgid" && $postate{type} ne "msgctxt") || ($n eq "msgctxt")); 56 checkpo(\%postate, \%all, $l, "line $linenum in $file", $keys, $new);93 checkpo(\%postate, \%all, $l, "line $linenum in $file", \%keys, $new, $use); 57 94 $postate{last} = $d; 58 95 $postate{type} = $n; … … 64 101 } 65 102 } 66 checkpo(\%postate, \%all, $l, "line $linenum in $file", $keys, 1);103 checkpo(\%postate, \%all, $l, "line $linenum in $file", \%keys, 1, $use); 67 104 } 68 105 else … … 70 107 die "File format not supported for file $file."; 71 108 } 72 $maxcount = $cnt if $cnt > $maxcount;73 109 close(FILE); 74 110 } … … 79 115 my $alwaysup = 0; 80 116 my $noask = 0; 81 my $conflicts;117 my %conflicts; 82 118 sub copystring($$$$$$$) 83 119 { … … 99 135 else 100 136 { 101 102 137 my $f = $data->{$en}{_file} || ""; 103 138 $f = ($f ? "$f;".$data->{$en}{"_src.$l"} : $data->{$en}{"_src.$l"}) if $data->{$en}{"_src.$l"}; … … 154 189 } 155 190 156 sub checkpo($$$$$$) 157 { 158 my ($postate, $data, $l, $txt, $keys, $new) = @_; 191 # Check a current state for new data 192 # 193 # @param postate Pointer to current status hash 194 # @param data Pointer to final data array 195 # @param l current language 196 # @param txt output text in case of error, usually file and line number 197 # @param keys pointer to hash for info keys extracted from the first msgid "" entry 198 # @param new whether a data set is finish or not yet complete 199 # @param use hash to strings to use or undef for all strings 200 # 201 sub checkpo($$$$$$$) 202 { 203 my ($postate, $data, $l, $txt, $keys, $new, $use) = @_; 159 204 160 205 if($postate->{type} eq "msgid") {$postate->{msgid} = $postate->{last};} … … 167 212 if($new) 168 213 { 169 if((!$postate->{fuzzy}) && $postate->{msgstr} && $postate->{msgid}) 214 my $en = $postate->{context} ? "___$postate->{context}___$postate->{msgid}" : $postate->{msgid}; 215 if((!$postate->{fuzzy}) && ($l eq "pot" || $postate->{msgstr}) && $postate->{msgid} 216 && (!$use || $use->{$en})) 170 217 { 171 218 copystring($data, $postate->{msgid}, $l, $postate->{msgstr},$txt,$postate->{context}, 1); 172 for($i = 1; exists($postate->{"msgstr_$i"}); ++$i) 173 { copystring($data, $postate->{msgid}, "$l.$i", $postate->{"msgstr_$i"},$txt,$postate->{context}, 1); } 174 if($postate->{msgid_1}) 175 { copystring($data, $postate->{msgid}, "en.1", $postate->{msgid_1},$txt,$postate->{context}, 1); } 219 if(!$use || $use->{$en}{"en.1"}) 220 { 221 for(my $i = 1; exists($postate->{"msgstr_$i"}); ++$i) 222 { copystring($data, $postate->{msgid}, "$l.$i", $postate->{"msgstr_$i"},$txt,$postate->{context}, 1); } 223 if($postate->{msgid_1}) 224 { copystring($data, $postate->{msgid}, "en.1", $postate->{msgid_1},$txt,$postate->{context}, 1); } 225 } 176 226 copystring($data, $postate->{msgid}, "_src.$l", $postate->{src},$txt,$postate->{context}, 1); 177 227 } … … 259 309 $maxlen = $len if $len > $maxlen; 260 310 } 311 my $maxcount = keys(%{$data}); 261 312 foreach my $file (@files) 262 313 { … … 306 357 { } 307 358 my $val; 308 $eq = 0;359 my $eq = 0; 309 360 if($la eq "en") 310 361 { … … 357 408 my %lang; 358 409 my @po; 359 my $basename = shift @ARGV; 410 my $potfile; 411 my $basename = "./"; 412 foreach my $arg (@ARGV) 413 { 414 next if $arg !~ /^--/; 415 if($arg =~ /^--basedir=(.+)$/) 416 { 417 $basename = $1; 418 } 419 elsif($arg =~ /^--potfile=(.+)$/) 420 { 421 $potfile = $1; 422 } 423 else 424 { 425 die "Unknown argument $arg."; 426 } 427 } 360 428 $basename .= "/" if !($basename =~ /[\/\\:]$/); 361 429 foreach my $arg (@ARGV) 362 430 { 431 next if $arg =~ /^--/; 363 432 foreach my $f (glob $arg) 364 433 { … … 368 437 } 369 438 } 370 my %data = loadfiles(\%lang,@po); 439 my %data = loadfiles(\%lang,$potfile ? loadpot($potfile) : undef, @po); 440 371 441 my @clang; 372 442 foreach my $la (sort keys %lang)
Note:
See TracChangeset
for help on using the changeset viewer.