119
121
elsif ($XML_STYLE_ARG && @ARGV > 2)
129
129
elsif ($KEYS_STYLE_ARG && @ARGV > 2)
134
&keys_merge_translations;
134
&keys_merge_translations;
137
137
elsif ($DESKTOP_STYLE_ARG && @ARGV > 2)
141
&desktop_merge_translations;
142
&desktop_merge_translations;
144
145
elsif ($SCHEMAS_STYLE_ARG && @ARGV > 2)
148
&schemas_merge_translations;
150
&schemas_merge_translations;
151
153
elsif ($RFC822DEB_STYLE_ARG && @ARGV > 2)
155
&rfc822deb_merge_translations;
157
&rfc822deb_merge_translations;
194
196
-x, --xml-style includes translations in the standard xml style
197
-u, --utf8 convert all strings to UTF-8 before merging
198
-p, --pass-through use strings as found in .po files, without
199
conversion (STRONGLY unrecommended with -x)
199
-u, --utf8 convert all strings to UTF-8 before merging
200
(default for everything except RFC822 style)
201
-p, --pass-through deprecated, does nothing and issues a warning
200
202
-m, --multiple-output output one localized file per locale, instead of
201
203
a single file containing all localized elements
202
204
-c, --cache=FILE specify cache file name
462
459
return "\\" if $sequence eq "\\\\";
463
460
return "\"" if $sequence eq "\\\"";
464
461
return "\n" if $sequence eq "\\n";
466
# gettext also handles \n, \t, \b, \r, \f, \v, \a, \xxx (octal),
467
# \xXX (hex) and has a comment saying they want to handle \u and \U.
462
return "\r" if $sequence eq "\\r";
463
return "\t" if $sequence eq "\\t";
464
return "\b" if $sequence eq "\\b";
465
return "\f" if $sequence eq "\\f";
466
return "\a" if $sequence eq "\\a";
467
return chr(11) if $sequence eq "\\v"; # vertical tab, see ascii(7)
469
return chr(hex($1)) if ($sequence =~ /\\x([0-9a-fA-F]{2})/);
470
return chr(oct($1)) if ($sequence =~ /\\([0-7]{3})/);
472
# FIXME: Is \0 supported as well? Kenneth and Rodney don't want it, see bug #48489
469
474
return $sequence;
504
508
my @list_of_chars = unpack ('C*', $pre_encoded);
506
if ($PASS_THROUGH_ARG)
508
return join ('', map (&entity_encode_int_even_high_bit, @list_of_chars));
512
# with UTF-8 we only encode minimalistic
513
return join ('', map (&entity_encode_int_minimalist, @list_of_chars));
510
# with UTF-8 we only encode minimalistic
511
return join ('', map (&entity_encode_int_minimalist, @list_of_chars));
517
514
sub entity_encode_int_minimalist
646
634
# Returns a translatable string from XML node, it works on contents of every node in XML::Parser tree
647
# doesn't support nesting of translatable tags (i.e. <_blah>this <_doh>doesn't</_doh> work</_blah> -- besides
648
# can you define the correct semantics for this?)
638
my $spacepreserve = shift || 0;
654
639
my @list = @{ $ref };
657
642
my $count = scalar(@list);
658
643
my $attrs = $list[0];
646
$spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/));
647
$spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/));
660
649
while ($index < $count) {
661
650
my $type = $list[$index];
662
651
my $content = $list[$index+1];
664
653
# We've got CDATA
666
655
# lets strip the whitespace here, and *ONLY* here
667
$content =~ s/\s+/ /gs;
668
$result .= ($content);
670
#print "no cdata content when expected it\n"; # is this possible, is this ok?
671
# what to do if this happens?
672
# Did I mention that I hate XML::Parser tree style?
656
$content =~ s/\s+/ /gs if (!$spacepreserve);
659
} elsif ( "$type" ne "1" ) {
675
660
# We've got another element
676
661
$result .= "<$type";
677
$result .= getAttributeString($attrs, 0); # no nested translatable elements
662
$result .= getAttributeString(@{$content}[0], 0); # no nested translatable elements
679
my $subresult = getXMLstring($content);
664
my $subresult = getXMLstring($content, $spacepreserve);
680
665
if ($subresult) {
681
666
$result .= ">".$subresult . "</$type>";
679
# Translate list of nodes if necessary
680
sub translate_subnodes
684
my $language = shift || "";
685
my $singlelang = shift || 0;
686
my $spacepreserve = shift || 0;
688
my @nodes = @{ $content };
690
my $count = scalar(@nodes);
692
while ($index < $count) {
693
my $type = $nodes[$index];
694
my $rest = $nodes[$index+1];
696
my $oldMO = $MULTIPLE_OUTPUT;
697
$MULTIPLE_OUTPUT = 1;
698
traverse($fh, $type, $rest, $language, $spacepreserve);
699
$MULTIPLE_OUTPUT = $oldMO;
701
traverse($fh, $type, $rest, $language, $spacepreserve);
707
sub isWellFormedXmlFragment
709
my $ret = eval 'require XML::Parser';
711
die "You must have XML::Parser installed to run $0\n\n";
714
my $fragment = shift;
715
return 0 if (!$fragment);
717
$fragment = "<root>$fragment</root>";
718
my $xp = new XML::Parser(Style => 'Tree');
720
eval { $tree = $xp->parse($fragment); };
697
727
my $nodename = shift;
698
728
my $content = shift;
699
729
my $language = shift || "";
730
my $spacepreserve = shift || 0;
701
732
if (!$nodename) {
702
733
if ($content =~ /^[\s]*$/) {
708
739
my @all = @{ $content };
709
740
my $attrs = shift @all;
710
my $outattr = getAttributeString($attrs, 1, $language);
711
741
my $translate = 0;
742
my $outattr = getAttributeString($attrs, 1, $language, \$translate);
713
744
if ($nodename =~ /^_/) {
715
746
$nodename =~ s/^_//;
718
print $fh "<$nodename$outattr";
750
$spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/));
751
$spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/));
753
print $fh "<$nodename", $outattr;
719
754
if ($translate) {
720
$lookup = getXMLstring($content);
721
$lookup =~ s/^\s+//s;
722
$lookup =~ s/\s+$//s;
725
my $translation = $translations{$language, $lookup};
726
if ($MULTIPLE_OUTPUT && $translation) {
727
print $fh " xml:lang=\"", $language, "\"";
728
print $fh ">", $translation, "</$nodename>";
755
$lookup = getXMLstring($content, $spacepreserve);
756
if (!$spacepreserve) {
757
$lookup =~ s/^\s+//s;
758
$lookup =~ s/\s+$//s;
761
if ($lookup || $translate == 2) {
762
my $translation = $translations{$language, $lookup} if isWellFormedXmlFragment($translations{$language, $lookup});
763
if ($MULTIPLE_OUTPUT && ($translation || $translate == 2)) {
764
$translation = $lookup if (!$translation);
765
print $fh " xml:lang=\"", $language, "\"" if $language;
767
if ($translate == 2) {
768
translate_subnodes($fh, \@all, $language, 1, $spacepreserve);
770
print $fh $translation;
772
print $fh "</$nodename>";
729
774
return; # this means there will be no same translation with xml:lang="$language"...
730
775
# if we want them both, just remove this "return"
732
print $fh ">$lookup</$nodename>";
778
if ($translate == 2) {
779
translate_subnodes($fh, \@all, $language, 1, $spacepreserve);
783
print $fh "</$nodename>";
739
789
for my $lang (sort keys %po_files_by_lang) {
740
790
if ($MULTIPLE_OUTPUT && $lang ne "$language") {
745
794
# Handle translation
747
my $localattrs = getAttributeString($attrs, 1, $lang);
748
my $decode_string = ($lookup); #entity_decode($lookup);
749
my $translation = $translations{$lang, $decode_string};
751
$translation = ($translation);
797
my $localattrs = getAttributeString($attrs, 1, $lang, \$translate);
798
my $translation = $translations{$lang, $lookup} if isWellFormedXmlFragment($translations{$lang, $lookup});
799
if ($translate && !$translation) {
800
$translation = $lookup;
803
if ($translation || $translate) {
753
805
$leading_space =~ s/.*\n//g;
754
806
print $fh $leading_space;
755
print $fh "<", $nodename, " xml:lang=\"", $lang, "\"", $localattrs;
756
print $fh ">", $translation , "</$nodename>";
807
print $fh "<", $nodename, " xml:lang=\"", $lang, "\"", $localattrs, ">";
808
if ($translate == 2) {
809
translate_subnodes($fh, \@all, $lang, 1, $spacepreserve);
811
print $fh $translation;
813
print $fh "</$nodename>";
762
819
my $count = scalar(@all);
763
820
if ($count > 0) {
769
while ($index < $count) {
770
my $type = $all[$index];
771
my $rest = $all[$index+1];
772
traverse($fh, $type, $rest, $language);
823
while ($index < $count) {
824
my $type = $all[$index];
825
my $rest = $all[$index+1];
826
traverse($fh, $type, $rest, $language, $spacepreserve);
776
829
print $fh "</$nodename>";
837
sub intltool_tree_comment
841
my $clist = $expat->{Curlist};
844
push @$clist, 1 => $data;
847
sub intltool_tree_cdatastart
850
my $clist = $expat->{Curlist};
853
push @$clist, 0 => $expat->original_string();
856
sub intltool_tree_cdataend
859
my $clist = $expat->{Curlist};
862
$clist->[$pos] .= $expat->original_string();
782
865
sub intltool_tree_char
784
867
my $expat = shift;