~ubuntu-branches/ubuntu/lucid/quick-lounge-applet/lucid

« back to all changes in this revision

Viewing changes to intltool-merge.in

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2008-09-22 18:01:12 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20080922180112-itm81kn3p09gduel
Tags: 2.12.5-5ubuntu1
* Merge from Debian unstable, remaining changes (LP: #273345):
 - Build-depend on xorg-dev, fix FTBFS.
 - Update Maintainer field as per spec. 
* Rebuild needed for libgnome-desktop-2 -> libgnome-desktop-2-7 transition

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.0";
 
38
my $VERSION = "0.36.2";
39
39
 
40
40
## Loaded modules
41
41
use strict; 
60
60
my $DESKTOP_STYLE_ARG = 0;
61
61
my $SCHEMAS_STYLE_ARG = 0;
62
62
my $RFC822DEB_STYLE_ARG = 0;
 
63
my $QUOTED_STYLE_ARG = 0;
63
64
my $QUIET_ARG = 0;
64
65
my $PASS_THROUGH_ARG = 0;
65
66
my $UTF8_ARG = 0;
79
80
 "desktop-style|d" => \$DESKTOP_STYLE_ARG,
80
81
 "schemas-style|s" => \$SCHEMAS_STYLE_ARG,
81
82
 "rfc822deb-style|r" => \$RFC822DEB_STYLE_ARG,
 
83
 "quoted-style" => \$QUOTED_STYLE_ARG,
82
84
 "pass-through|p" => \$PASS_THROUGH_ARG,
83
85
 "utf8|u" => \$UTF8_ARG,
84
86
 "multiple-output|m" => \$MULTIPLE_OUTPUT,
91
93
 
92
94
my %po_files_by_lang = ();
93
95
my %translations = ();
94
 
my $iconv = $ENV{"ICONV"} || $ENV{"INTLTOOL_ICONV"} || "@INTLTOOL_ICONV@";
 
96
my $iconv = $ENV{"ICONV"} || "iconv";
95
97
my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null');
96
98
 
 
99
sub isProgramInPath
 
100
{
 
101
    my ($file) = @_;
 
102
    # If either a file exists, or when run it returns 0 exit status
 
103
    return 1 if ((-x $file) or (system("$file -l >$devnull") == 0));
 
104
    return 0;
 
105
}
 
106
 
 
107
if (! isProgramInPath ("$iconv"))
 
108
{
 
109
        print STDERR " *** iconv is not found on this system!\n".
 
110
                     " *** Without it, intltool-merge can not convert encodings.\n";
 
111
        exit;
 
112
}
 
113
 
97
114
# Use this instead of \w for XML files to handle more possible characters.
98
115
my $w = "[-A-Za-z0-9._:]";
99
116
 
157
174
        &rfc822deb_merge_translations;
158
175
        &finalize;
159
176
 
177
elsif ($QUOTED_STYLE_ARG && @ARGV > 2) 
 
178
{
 
179
        &utf8_sanity_check;
 
180
        &preparation;
 
181
        &print_message;
 
182
        &quoted_merge_translations;
 
183
        &finalize;
 
184
160
185
else 
161
186
{
162
187
        &print_help;
193
218
  -k, --keys-style       includes translations in the keys style
194
219
  -s, --schemas-style    includes translations in the schemas style
195
220
  -r, --rfc822deb-style  includes translations in the RFC822 style
 
221
      --quoted-style     includes translations in the quoted string style
196
222
  -x, --xml-style        includes translations in the standard xml style
197
223
 
198
224
Other options:
249
275
 
250
276
sub gather_po_files
251
277
{
252
 
    for my $po_file (glob "$PO_DIR/*.po") {
253
 
        $po_files_by_lang{po_file2lang($po_file)} = $po_file;
 
278
    if (my $linguas = $ENV{"LINGUAS"})
 
279
    {
 
280
        for my $lang (split / /, $linguas) {
 
281
            my $po_file = $PO_DIR . "/" . $lang . ".po";
 
282
            if (-e $po_file) {
 
283
                $po_files_by_lang{$lang} = $po_file;
 
284
            }
 
285
        }
 
286
    }
 
287
    else
 
288
    {
 
289
        if (open LINGUAS_FILE, "$PO_DIR/LINGUAS")
 
290
        {
 
291
            while (<LINGUAS_FILE>)
 
292
            {
 
293
                next if /^#/;
 
294
 
 
295
                if (/([-a-zA-Z_@.]+)\n/)
 
296
                {
 
297
                    my $lang = $1;
 
298
 
 
299
                    my $po_file = $PO_DIR . "/" . $lang . ".po";
 
300
                    if (-e $po_file) {
 
301
                        $po_files_by_lang{$lang} = $po_file;
 
302
                    }
 
303
                }
 
304
            }
 
305
 
 
306
            close LINGUAS_FILE;
 
307
        }
 
308
        else
 
309
        {
 
310
            for my $po_file (glob "$PO_DIR/*.po") {
 
311
                $po_files_by_lang{po_file2lang($po_file)} = $po_file;
 
312
            }
 
313
        }
254
314
    }
255
315
}
256
316
 
415
475
        {
416
476
            $nextfuzzy = 1 if /^#, fuzzy/;
417
477
       
418
 
            if (/^msgid "((\\.|[^\\])*)"/ ) 
 
478
            if (/^msgid "((\\.|[^\\]+)*)"/ ) 
419
479
            {
420
480
                $translations{$lang, $msgid} = $msgstr if $inmsgstr && $msgid && $msgstr;
421
481
                $msgid = "";
431
491
                $nextfuzzy = 0;
432
492
            }
433
493
 
434
 
            if (/^msgstr "((\\.|[^\\])*)"/) 
 
494
            if (/^msgstr "((\\.|[^\\]+)*)"/) 
435
495
            {
436
496
                $msgstr = unescape_po_string($1);
437
497
                $inmsgstr = 1;
438
498
                $inmsgid = 0;
439
499
            }
440
500
 
441
 
            if (/^"((\\.|[^\\])*)"/) 
 
501
            if (/^"((\\.|[^\\]+)*)"/) 
442
502
            {
443
503
                $msgid .= unescape_po_string($1) if $inmsgid;
444
504
                $msgstr .= unescape_po_string($1) if $inmsgstr;
483
543
    return $string;
484
544
}
485
545
 
486
 
## NOTE: deal with < - &lt; but not > - &gt;  because it seems its ok to have 
487
 
## > in the entity. For further info please look at #84738.
488
546
sub entity_decode
489
547
{
490
548
    local ($_) = @_;
491
549
 
492
550
    s/&apos;/'/g; # '
493
551
    s/&quot;/"/g; # "
 
552
    s/&lt;/</g;
 
553
    s/&gt;/>/g;
494
554
    s/&amp;/&/g;
495
 
    s/&lt;/</g;
496
555
 
497
556
    return $_;
498
557
}
1006
1065
 
1007
1066
    if ($MULTIPLE_OUTPUT) {
1008
1067
        for my $lang (sort keys %po_files_by_lang) {
1009
 
            if ( ! -e $lang ) {
1010
 
                mkdir $lang or die "Cannot create subdirectory $lang: $!\n";
 
1068
            if ( ! -d $lang ) {
 
1069
                mkdir $lang or -d $lang or die "Cannot create subdirectory $lang: $!\n";
1011
1070
            }
1012
1071
            open OUTPUT, ">$lang/$OUTFILE" or die "Cannot open $lang/$OUTFILE: $!\n";
1013
1072
            binmode (OUTPUT) if $^O eq 'MSWin32';
1354
1413
    return @list;
1355
1414
}
1356
1415
 
 
1416
sub quoted_translation
 
1417
{
 
1418
    my ($lang, $string) = @_;
 
1419
 
 
1420
    $string =~ s/\\\"/\"/g;
 
1421
 
 
1422
    my $translation = $translations{$lang, $string};
 
1423
    $translation = $string if !$translation;
 
1424
 
 
1425
    $translation =~ s/\"/\\\"/g;
 
1426
    return $translation
 
1427
}
 
1428
 
 
1429
sub quoted_merge_translations
 
1430
{
 
1431
    if (!$MULTIPLE_OUTPUT) {
 
1432
        print "Quoted only supports Multiple Output.\n";
 
1433
        exit(1);
 
1434
    }
 
1435
 
 
1436
    for my $lang (sort keys %po_files_by_lang) {
 
1437
        if ( ! -d $lang ) {
 
1438
            mkdir $lang or -d $lang or die "Cannot create subdirectory $lang: $!\n";
 
1439
        }
 
1440
        open INPUT, "<${FILE}" or die;
 
1441
        open OUTPUT, ">$lang/$OUTFILE" or die "Cannot open $lang/$OUTFILE: $!\n";
 
1442
        binmode (OUTPUT) if $^O eq 'MSWin32';
 
1443
        while (<INPUT>) 
 
1444
        {
 
1445
            s/\"(([^\"]|\\\")*[^\\\"])\"/"\"" . &quoted_translation($lang, $1) . "\""/ge;
 
1446
            print OUTPUT;
 
1447
        }
 
1448
        close OUTPUT;
 
1449
        close INPUT;
 
1450
    }
 
1451
}