~ubuntu-branches/ubuntu/trusty/last-exit/trusty

« back to all changes in this revision

Viewing changes to intltool-merge.in

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2008-03-21 00:53:20 UTC
  • mfrom: (1.1.5 upstream) (4.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080321005320-u2l6gaaxn2mn0mbq
Tags: 6-1
* New upstream release:
  + debian/patches/01_dllmaps.patch,
    debian/patches/02_de.po.patch,
    debian/patches/03_gtk-sharp-2-12.patch:
    - Dropped, merged upstream.
  + debian/control.in:
    - Update build dependencies.
  + debian/patches/99_ltmain_as-needed.patch:
    - Updated to apply cleanly again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
## Release information
36
36
my $PROGRAM = "intltool-merge";
37
37
my $PACKAGE = "intltool";
38
 
my $VERSION = "0.35.5";
 
38
my $VERSION = "0.37.1";
39
39
 
40
40
## Loaded modules
41
41
use strict; 
61
61
my $SCHEMAS_STYLE_ARG = 0;
62
62
my $RFC822DEB_STYLE_ARG = 0;
63
63
my $QUOTED_STYLE_ARG = 0;
 
64
my $QUOTEDXML_STYLE_ARG = 0;
64
65
my $QUIET_ARG = 0;
65
66
my $PASS_THROUGH_ARG = 0;
66
67
my $UTF8_ARG = 0;
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,
93
95
 
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');
98
100
 
 
101
sub isProgramInPath
 
102
{
 
103
    my ($file) = @_;
 
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));
 
106
    return 0;
 
107
}
 
108
 
 
109
if (! isProgramInPath ("$iconv"))
 
110
{
 
111
        print STDERR " *** iconv is not found on this system!\n".
 
112
                     " *** Without it, intltool-merge can not convert encodings.\n";
 
113
        exit;
 
114
}
 
115
 
99
116
# Use this instead of \w for XML files to handle more possible characters.
100
117
my $w = "[-A-Za-z0-9._:]";
101
118
 
133
150
        &utf8_sanity_check;
134
151
        &preparation;
135
152
        &print_message;
136
 
        &keys_merge_translations;
 
153
        &keys_merge_translations;
137
154
        &finalize;
138
155
139
156
elsif ($DESKTOP_STYLE_ARG && @ARGV > 2) 
159
176
        &rfc822deb_merge_translations;
160
177
        &finalize;
161
178
162
 
elsif ($QUOTED_STYLE_ARG && @ARGV > 2) 
 
179
elsif (($QUOTED_STYLE_ARG || $QUOTEDXML_STYLE_ARG) && @ARGV > 2)
163
180
{
164
181
        &utf8_sanity_check;
165
182
        &preparation;
166
183
        &print_message;
167
 
        &quoted_merge_translations;
 
184
        &quoted_merge_translations($QUOTEDXML_STYLE_ARG);
168
185
        &finalize;
169
186
170
187
else 
204
221
  -s, --schemas-style    includes translations in the schemas style
205
222
  -r, --rfc822deb-style  includes translations in the RFC822 style
206
223
      --quoted-style     includes translations in the quoted string style
 
224
      --quotedxml-style  includes translations in the quoted xml string style
207
225
  -x, --xml-style        includes translations in the standard xml style
208
226
 
209
227
Other options:
260
278
 
261
279
sub gather_po_files
262
280
{
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"})
 
282
    {
 
283
        for my $lang (split / /, $linguas) {
 
284
            my $po_file = $PO_DIR . "/" . $lang . ".po";
 
285
            if (-e $po_file) {
 
286
                $po_files_by_lang{$lang} = $po_file;
 
287
            }
 
288
        }
 
289
    }
 
290
    else
 
291
    {
 
292
        if (open LINGUAS_FILE, "$PO_DIR/LINGUAS")
 
293
        {
 
294
            while (<LINGUAS_FILE>)
 
295
            {
 
296
                next if /^#/;
 
297
 
 
298
                for my $lang (split)
 
299
                {
 
300
                    chomp ($lang);
 
301
                    my $po_file = $PO_DIR . "/" . $lang . ".po";
 
302
                    if (-e $po_file) {
 
303
                        $po_files_by_lang{$lang} = $po_file;
 
304
                    }
 
305
                }
 
306
            }
 
307
 
 
308
            close LINGUAS_FILE;
 
309
        }
 
310
        else
 
311
        {
 
312
            for my $po_file (glob "$PO_DIR/*.po") {
 
313
                $po_files_by_lang{po_file2lang($po_file)} = $po_file;
 
314
            }
 
315
        }
265
316
    }
266
317
}
267
318
 
494
545
    return $string;
495
546
}
496
547
 
497
 
## NOTE: deal with < - &lt; but not > - &gt;  because it seems its ok to have 
498
 
## > in the entity. For further info please look at #84738.
499
548
sub entity_decode
500
549
{
501
550
    local ($_) = @_;
502
551
 
503
552
    s/&apos;/'/g; # '
504
553
    s/&quot;/"/g; # "
 
554
    s/&lt;/</g;
 
555
    s/&gt;/>/g;
505
556
    s/&amp;/&/g;
506
 
    s/&lt;/</g;
507
557
 
508
558
    return $_;
509
559
}
528
578
    return "&amp;" if $_ == 38;
529
579
    return "&apos;" if $_ == 39;
530
580
    return "&lt;" if $_ == 60;
 
581
    return "&gt;" if $_ == 62;
531
582
    return chr $_;
532
583
}
533
584
 
1028
1079
            close OUTPUT;
1029
1080
            print "CREATED $lang/$OUTFILE\n" unless $QUIET_ARG;
1030
1081
        }
1031
 
    } 
1032
 
    open OUTPUT, ">$OUTFILE" or die "Cannot open $OUTFILE: $!\n";
 
1082
        if ( ! -d "C" ) {
 
1083
            mkdir "C" or -d "C" or die "Cannot create subdirectory C: $!\n";
 
1084
        }
 
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);
 
1090
        close OUTPUT;
 
1091
        print "CREATED C/$OUTFILE\n" unless $QUIET_ARG;
 
1092
    } else {
 
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);
 
1098
        close OUTPUT;
 
1099
        print "CREATED $OUTFILE\n" unless $QUIET_ARG;
 
1100
    }
 
1101
}
 
1102
 
 
1103
sub keys_merge_translation
 
1104
{
 
1105
    my ($lang) = @_;
 
1106
 
 
1107
    if ( ! -d $lang && $MULTIPLE_OUTPUT)
 
1108
    {
 
1109
        mkdir $lang or -d $lang or die "Cannot create subdirectory $lang: $!\n";
 
1110
    }
 
1111
 
 
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);
 
1115
 
 
1116
    while (<INPUT>)
 
1117
    {
 
1118
        if (s/^(\s*)_(\w+=(.*))/$1$2/)
 
1119
        {
 
1120
            my $string = $3;
 
1121
 
 
1122
            if (!$MULTIPLE_OUTPUT)
 
1123
            {
 
1124
                print OUTPUT;
 
1125
 
 
1126
                my $non_translated_line = $_;
 
1127
 
 
1128
                for my $lang (sort keys %po_files_by_lang)
 
1129
                {
 
1130
                    my $translation = $translations{$lang, $string};
 
1131
                    next if !$translation;
 
1132
 
 
1133
                    $_ = $non_translated_line;
 
1134
                    s/(\w+)=.*/[$lang]$1=$translation/;
 
1135
                    print OUTPUT;
 
1136
                }
 
1137
            }
 
1138
            else
 
1139
            {
 
1140
                my $non_translated_line = $_;
 
1141
                my $translation = $translations{$lang, $string};
 
1142
                $translation = $string if !$translation;
 
1143
 
 
1144
                $_ = $non_translated_line;
 
1145
                s/(\w+)=.*/$1=$translation/;
 
1146
                print OUTPUT;
 
1147
            }
 
1148
        }
 
1149
        else
 
1150
        {
 
1151
            print OUTPUT;
 
1152
        }
 
1153
    }
 
1154
 
1037
1155
    close OUTPUT;
1038
 
    print "CREATED $OUTFILE\n" unless $QUIET_ARG;
 
1156
    close INPUT;
 
1157
 
 
1158
    print "CREATED $lang/$OUTFILE\n" unless $QUIET_ARG;
1039
1159
}
1040
1160
 
1041
1161
sub keys_merge_translations
1042
1162
{
1043
 
    open INPUT, "<${FILE}" or die;
1044
 
    open OUTPUT, ">${OUTFILE}" or die;
1045
 
    binmode (OUTPUT) if $^O eq 'MSWin32';
1046
 
 
1047
 
    while (<INPUT>) 
 
1163
    if ($MULTIPLE_OUTPUT)
1048
1164
    {
1049
 
        if (s/^(\s*)_(\w+=(.*))/$1$2/)  
1050
 
        {
1051
 
            my $string = $3;
1052
 
 
1053
 
            print OUTPUT;
1054
 
 
1055
 
            my $non_translated_line = $_;
1056
 
 
1057
 
            for my $lang (sort keys %po_files_by_lang) 
1058
 
            {
1059
 
                my $translation = $translations{$lang, $string};
1060
 
                next if !$translation;
1061
 
 
1062
 
                $_ = $non_translated_line;
1063
 
                s/(\w+)=.*/[$lang]$1=$translation/;
1064
 
                print OUTPUT;
1065
 
            }
1066
 
        } 
1067
 
        else 
1068
 
        {
1069
 
            print OUTPUT;
 
1165
        for my $lang (sort keys %po_files_by_lang)
 
1166
        {
 
1167
            keys_merge_translation ($lang);
1070
1168
        }
1071
 
    }
1072
 
 
1073
 
    close OUTPUT;
1074
 
    close INPUT;
 
1169
        keys_merge_translation ("C");
 
1170
    }
 
1171
    else
 
1172
    {
 
1173
        keys_merge_translation (".");
 
1174
    }
1075
1175
}
1076
1176
 
1077
1177
sub desktop_merge_translations
1367
1467
 
1368
1468
sub quoted_translation
1369
1469
{
1370
 
    my ($lang, $string) = @_;
 
1470
    my ($xml_mode, $lang, $string) = @_;
1371
1471
 
 
1472
    $string = entity_decode($string) if $xml_mode;
1372
1473
    $string =~ s/\\\"/\"/g;
1373
1474
 
1374
1475
    my $translation = $translations{$lang, $string};
1375
1476
    $translation = $string if !$translation;
1376
 
 
 
1477
    $translation = entity_encode($translation) if $xml_mode;
1377
1478
    $translation =~ s/\"/\\\"/g;
1378
1479
    return $translation
1379
1480
}
1380
1481
 
1381
1482
sub quoted_merge_translations
1382
1483
{
 
1484
    my ($xml_mode) = @_;
 
1485
 
1383
1486
    if (!$MULTIPLE_OUTPUT) {
1384
1487
        print "Quoted only supports Multiple Output.\n";
1385
1488
        exit(1);
1394
1497
        binmode (OUTPUT) if $^O eq 'MSWin32';
1395
1498
        while (<INPUT>) 
1396
1499
        {
1397
 
            s/\"(([^\"]|\\\")*[^\\\"])\"/"\"" . &quoted_translation($lang, $1) . "\""/ge;
 
1500
            s/\"(([^\"]|\\\")*[^\\\"])\"/"\"" . &quoted_translation($xml_mode, $lang, $1) . "\""/ge;
1398
1501
            print OUTPUT;
1399
1502
        }
1400
1503
        close OUTPUT;