~ubuntu-branches/ubuntu/intrepid/zenity/intrepid

« back to all changes in this revision

Viewing changes to intltool-merge.in

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-02-29 12:11:11 UTC
  • mfrom: (1.1.26 upstream)
  • Revision ID: james.westby@ubuntu.com-20080229121111-szkn3cxwn6tajrp9
Tags: 2.21.1-0ubuntu1
* New upstream release:
  - documentation and translation updates
* Modify Maintainer value to match the DebianMaintainerField
  specification.

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.36.1";
 
38
my $VERSION = "0.37.0";
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,
148
150
        &utf8_sanity_check;
149
151
        &preparation;
150
152
        &print_message;
151
 
        &keys_merge_translations;
 
153
        &keys_merge_translations;
152
154
        &finalize;
153
155
154
156
elsif ($DESKTOP_STYLE_ARG && @ARGV > 2) 
174
176
        &rfc822deb_merge_translations;
175
177
        &finalize;
176
178
177
 
elsif ($QUOTED_STYLE_ARG && @ARGV > 2) 
 
179
elsif (($QUOTED_STYLE_ARG || $QUOTEDXML_STYLE_ARG) && @ARGV > 2)
178
180
{
179
181
        &utf8_sanity_check;
180
182
        &preparation;
181
183
        &print_message;
182
 
        &quoted_merge_translations;
 
184
        &quoted_merge_translations($QUOTEDXML_STYLE_ARG);
183
185
        &finalize;
184
186
185
187
else 
219
221
  -s, --schemas-style    includes translations in the schemas style
220
222
  -r, --rfc822deb-style  includes translations in the RFC822 style
221
223
      --quoted-style     includes translations in the quoted string style
 
224
      --quotedxml-style  includes translations in the quoted xml string style
222
225
  -x, --xml-style        includes translations in the standard xml style
223
226
 
224
227
Other options:
575
578
    return "&" if $_ == 38;
576
579
    return "'" if $_ == 39;
577
580
    return "<" if $_ == 60;
 
581
    return ">" if $_ == 62;
578
582
    return chr $_;
579
583
}
580
584
 
1075
1079
            close OUTPUT;
1076
1080
            print "CREATED $lang/$OUTFILE\n" unless $QUIET_ARG;
1077
1081
        }
1078
 
    } 
1079
 
    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";
1080
1114
    binmode (OUTPUT) if $^O eq 'MSWin32';
1081
 
    my $tree = readXml($FILE);
1082
 
    print_header($FILE, \*OUTPUT);
1083
 
    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
 
1084
1155
    close OUTPUT;
1085
 
    print "CREATED $OUTFILE\n" unless $QUIET_ARG;
 
1156
    close INPUT;
 
1157
 
 
1158
    print "CREATED $lang/$OUTFILE\n" unless $QUIET_ARG;
1086
1159
}
1087
1160
 
1088
1161
sub keys_merge_translations
1089
1162
{
1090
 
    open INPUT, "<${FILE}" or die;
1091
 
    open OUTPUT, ">${OUTFILE}" or die;
1092
 
    binmode (OUTPUT) if $^O eq 'MSWin32';
1093
 
 
1094
 
    while (<INPUT>) 
 
1163
    if ($MULTIPLE_OUTPUT)
1095
1164
    {
1096
 
        if (s/^(\s*)_(\w+=(.*))/$1$2/)  
1097
 
        {
1098
 
            my $string = $3;
1099
 
 
1100
 
            print OUTPUT;
1101
 
 
1102
 
            my $non_translated_line = $_;
1103
 
 
1104
 
            for my $lang (sort keys %po_files_by_lang) 
1105
 
            {
1106
 
                my $translation = $translations{$lang, $string};
1107
 
                next if !$translation;
1108
 
 
1109
 
                $_ = $non_translated_line;
1110
 
                s/(\w+)=.*/[$lang]$1=$translation/;
1111
 
                print OUTPUT;
1112
 
            }
1113
 
        } 
1114
 
        else 
1115
 
        {
1116
 
            print OUTPUT;
 
1165
        for my $lang (sort keys %po_files_by_lang)
 
1166
        {
 
1167
            keys_merge_translation ($lang);
1117
1168
        }
1118
 
    }
1119
 
 
1120
 
    close OUTPUT;
1121
 
    close INPUT;
 
1169
        keys_merge_translation ("C");
 
1170
    }
 
1171
    else
 
1172
    {
 
1173
        keys_merge_translation (".");
 
1174
    }
1122
1175
}
1123
1176
 
1124
1177
sub desktop_merge_translations
1414
1467
 
1415
1468
sub quoted_translation
1416
1469
{
1417
 
    my ($lang, $string) = @_;
 
1470
    my ($xml_mode, $lang, $string) = @_;
1418
1471
 
 
1472
    $string = entity_decode($string) if $xml_mode;
1419
1473
    $string =~ s/\\\"/\"/g;
1420
1474
 
1421
1475
    my $translation = $translations{$lang, $string};
1422
1476
    $translation = $string if !$translation;
1423
 
 
 
1477
    $translation = entity_encode($translation) if $xml_mode;
1424
1478
    $translation =~ s/\"/\\\"/g;
1425
1479
    return $translation
1426
1480
}
1427
1481
 
1428
1482
sub quoted_merge_translations
1429
1483
{
 
1484
    my ($xml_mode) = @_;
 
1485
 
1430
1486
    if (!$MULTIPLE_OUTPUT) {
1431
1487
        print "Quoted only supports Multiple Output.\n";
1432
1488
        exit(1);
1441
1497
        binmode (OUTPUT) if $^O eq 'MSWin32';
1442
1498
        while (<INPUT>) 
1443
1499
        {
1444
 
            s/\"(([^\"]|\\\")*[^\\\"])\"/"\"" . &quoted_translation($lang, $1) . "\""/ge;
 
1500
            s/\"(([^\"]|\\\")*[^\\\"])\"/"\"" . &quoted_translation($xml_mode, $lang, $1) . "\""/ge;
1445
1501
            print OUTPUT;
1446
1502
        }
1447
1503
        close OUTPUT;