81
82
"schemas-style|s" => \$SCHEMAS_STYLE_ARG,
82
83
"rfc822deb-style|r" => \$RFC822DEB_STYLE_ARG,
83
84
"quoted-style" => \$QUOTED_STYLE_ARG,
85
"quotedxml-style" => \$QUOTEDXML_STYLE_ARG,
84
86
"pass-through|p" => \$PASS_THROUGH_ARG,
85
87
"utf8|u" => \$UTF8_ARG,
86
88
"multiple-output|m" => \$MULTIPLE_OUTPUT,
94
96
my %po_files_by_lang = ();
95
97
my %translations = ();
96
my $iconv = $ENV{"ICONV"} || $ENV{"INTLTOOL_ICONV"} || "@INTLTOOL_ICONV@";
98
my $iconv = $ENV{"ICONV"} || "iconv";
97
99
my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null');
104
# If either a file exists, or when run it returns 0 exit status
105
return 1 if ((-x $file) or (system("$file -l >$devnull") == 0));
109
if (! isProgramInPath ("$iconv"))
111
print STDERR " *** iconv is not found on this system!\n".
112
" *** Without it, intltool-merge can not convert encodings.\n";
99
116
# Use this instead of \w for XML files to handle more possible characters.
100
117
my $w = "[-A-Za-z0-9._:]";
261
279
sub gather_po_files
263
for my $po_file (glob "$PO_DIR/*.po") {
264
$po_files_by_lang{po_file2lang($po_file)} = $po_file;
281
if (my $linguas = $ENV{"LINGUAS"})
283
for my $lang (split / /, $linguas) {
284
my $po_file = $PO_DIR . "/" . $lang . ".po";
286
$po_files_by_lang{$lang} = $po_file;
292
if (open LINGUAS_FILE, "$PO_DIR/LINGUAS")
294
while (<LINGUAS_FILE>)
301
my $po_file = $PO_DIR . "/" . $lang . ".po";
303
$po_files_by_lang{$lang} = $po_file;
312
for my $po_file (glob "$PO_DIR/*.po") {
313
$po_files_by_lang{po_file2lang($po_file)} = $po_file;
1029
1080
print "CREATED $lang/$OUTFILE\n" unless $QUIET_ARG;
1032
open OUTPUT, ">$OUTFILE" or die "Cannot open $OUTFILE: $!\n";
1083
mkdir "C" or -d "C" or die "Cannot create subdirectory C: $!\n";
1085
open OUTPUT, ">C/$OUTFILE" or die "Cannot open C/$OUTFILE: $!\n";
1086
binmode (OUTPUT) if $^O eq 'MSWin32';
1087
my $tree = readXml($FILE);
1088
print_header($FILE, \*OUTPUT);
1089
parseTree(\*OUTPUT, $tree);
1091
print "CREATED C/$OUTFILE\n" unless $QUIET_ARG;
1093
open OUTPUT, ">$OUTFILE" or die "Cannot open $OUTFILE: $!\n";
1094
binmode (OUTPUT) if $^O eq 'MSWin32';
1095
my $tree = readXml($FILE);
1096
print_header($FILE, \*OUTPUT);
1097
parseTree(\*OUTPUT, $tree);
1099
print "CREATED $OUTFILE\n" unless $QUIET_ARG;
1103
sub keys_merge_translation
1107
if ( ! -d $lang && $MULTIPLE_OUTPUT)
1109
mkdir $lang or -d $lang or die "Cannot create subdirectory $lang: $!\n";
1112
open INPUT, "<${FILE}" or die "Cannot open ${FILE}: $!\n";
1113
open OUTPUT, ">$lang/$OUTFILE" or die "Cannot open $lang/$OUTFILE: $!\n";
1033
1114
binmode (OUTPUT) if $^O eq 'MSWin32';
1034
my $tree = readXml($FILE);
1035
print_header($FILE, \*OUTPUT);
1036
parseTree(\*OUTPUT, $tree);
1118
if (s/^(\s*)_(\w+=(.*))/$1$2/)
1122
if (!$MULTIPLE_OUTPUT)
1126
my $non_translated_line = $_;
1128
for my $lang (sort keys %po_files_by_lang)
1130
my $translation = $translations{$lang, $string};
1131
next if !$translation;
1133
$_ = $non_translated_line;
1134
s/(\w+)=.*/[$lang]$1=$translation/;
1140
my $non_translated_line = $_;
1141
my $translation = $translations{$lang, $string};
1142
$translation = $string if !$translation;
1144
$_ = $non_translated_line;
1145
s/(\w+)=.*/$1=$translation/;
1038
print "CREATED $OUTFILE\n" unless $QUIET_ARG;
1158
print "CREATED $lang/$OUTFILE\n" unless $QUIET_ARG;
1041
1161
sub keys_merge_translations
1043
open INPUT, "<${FILE}" or die;
1044
open OUTPUT, ">${OUTFILE}" or die;
1045
binmode (OUTPUT) if $^O eq 'MSWin32';
1163
if ($MULTIPLE_OUTPUT)
1049
if (s/^(\s*)_(\w+=(.*))/$1$2/)
1055
my $non_translated_line = $_;
1057
for my $lang (sort keys %po_files_by_lang)
1059
my $translation = $translations{$lang, $string};
1060
next if !$translation;
1062
$_ = $non_translated_line;
1063
s/(\w+)=.*/[$lang]$1=$translation/;
1165
for my $lang (sort keys %po_files_by_lang)
1167
keys_merge_translation ($lang);
1169
keys_merge_translation ("C");
1173
keys_merge_translation (".");
1077
1177
sub desktop_merge_translations
1368
1468
sub quoted_translation
1370
my ($lang, $string) = @_;
1470
my ($xml_mode, $lang, $string) = @_;
1472
$string = entity_decode($string) if $xml_mode;
1372
1473
$string =~ s/\\\"/\"/g;
1374
1475
my $translation = $translations{$lang, $string};
1375
1476
$translation = $string if !$translation;
1477
$translation = entity_encode($translation) if $xml_mode;
1377
1478
$translation =~ s/\"/\\\"/g;
1378
1479
return $translation
1381
1482
sub quoted_merge_translations
1484
my ($xml_mode) = @_;
1383
1486
if (!$MULTIPLE_OUTPUT) {
1384
1487
print "Quoted only supports Multiple Output.\n";