2
# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*-
5
# The Intltool Message Merger
7
# Copyright (C) 2000, 2003 Free Software Foundation.
8
# Copyright (C) 2000, 2001 Eazel, Inc
10
# Intltool is free software; you can redistribute it and/or
11
# modify it under the terms of the GNU General Public License
12
# version 2 published by the Free Software Foundation.
14
# Intltool is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
# General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
# As a special exception to the GNU General Public License, if you
24
# distribute this file as part of a program that contains a
25
# configuration script generated by Autoconf, you may include it under
26
# the same distribution terms that you use for the rest of that program.
28
# Authors: Maciej Stachowiak <mjs@noisehavoc.org>
29
# Kenneth Christiansen <kenneth@gnu.org>
30
# Darin Adler <darin@bentspoon.com>
32
# Proper XML UTF-8'ification written by Cyrille Chepelov <chepelov@calixo.net>
35
## Release information
36
my $PROGRAM = "intltool-merge";
37
my $PACKAGE = "intltool";
38
my $VERSION = "0.32.1";
46
my $must_end_tag = -1;
48
my $translation_depth = -1;
51
my @translation_strings = ();
52
my $leading_space = "";
54
## Scalars used by the option stuff
58
my $XML_STYLE_ARG = 0;
59
my $KEYS_STYLE_ARG = 0;
60
my $DESKTOP_STYLE_ARG = 0;
61
my $SCHEMAS_STYLE_ARG = 0;
62
my $RFC822DEB_STYLE_ARG = 0;
64
my $PASS_THROUGH_ARG = 0;
66
my $MULTIPLE_OUTPUT = 0;
73
"version" => \$VERSION_ARG,
74
"quiet|q" => \$QUIET_ARG,
75
"oaf-style|o" => \$BA_STYLE_ARG, ## for compatibility
76
"ba-style|b" => \$BA_STYLE_ARG,
77
"xml-style|x" => \$XML_STYLE_ARG,
78
"keys-style|k" => \$KEYS_STYLE_ARG,
79
"desktop-style|d" => \$DESKTOP_STYLE_ARG,
80
"schemas-style|s" => \$SCHEMAS_STYLE_ARG,
81
"rfc822deb-style|r" => \$RFC822DEB_STYLE_ARG,
82
"pass-through|p" => \$PASS_THROUGH_ARG,
83
"utf8|u" => \$UTF8_ARG,
84
"multiple-output|m" => \$MULTIPLE_OUTPUT,
85
"cache|c=s" => \$cache_file
92
my %po_files_by_lang = ();
93
my %translations = ();
94
my $iconv = $ENV{"ICONV"} || $ENV{"INTLTOOL_ICONV"} || "@INTLTOOL_ICONV@";
96
# Use this instead of \w for XML files to handle more possible characters.
97
my $w = "[-A-Za-z0-9._:]";
99
# XML quoted string contents
102
## Check for options.
112
elsif ($BA_STYLE_ARG && @ARGV > 2)
117
&ba_merge_translations;
120
elsif ($XML_STYLE_ARG && @ARGV > 2)
128
elsif ($KEYS_STYLE_ARG && @ARGV > 2)
133
&keys_merge_translations;
136
elsif ($DESKTOP_STYLE_ARG && @ARGV > 2)
141
&desktop_merge_translations;
144
elsif ($SCHEMAS_STYLE_ARG && @ARGV > 2)
149
&schemas_merge_translations;
152
elsif ($RFC822DEB_STYLE_ARG && @ARGV > 2)
156
&rfc822deb_merge_translations;
166
## Sub for printing release information
170
${PROGRAM} (${PACKAGE}) ${VERSION}
171
Written by Maciej Stachowiak, Darin Adler and Kenneth Christiansen.
173
Copyright (C) 2000-2003 Free Software Foundation, Inc.
174
Copyright (C) 2000-2001 Eazel, Inc.
175
This is free software; see the source for copying conditions. There is NO
176
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
181
## Sub for printing usage information
185
Usage: ${PROGRAM} [OPTION]... PO_DIRECTORY FILENAME OUTPUT_FILE
186
Generates an output file that includes some localized attributes from an
187
untranslated source file.
189
Mandatory options: (exactly one must be specified)
190
-b, --ba-style includes translations in the bonobo-activation style
191
-d, --desktop-style includes translations in the desktop style
192
-k, --keys-style includes translations in the keys style
193
-s, --schemas-style includes translations in the schemas style
194
-r, --rfc822deb-style includes translations in the RFC822 style
195
-x, --xml-style includes translations in the standard xml style
198
-u, --utf8 convert all strings to UTF-8 before merging
199
(default for everything except RFC822 style)
200
-p, --pass-through deprecated, does nothing and issues a warning
201
-m, --multiple-output output one localized file per locale, instead of
202
a single file containing all localized elements
203
-c, --cache=FILE specify cache file name
204
(usually \$top_builddir/po/.intltool-merge-cache)
205
-q, --quiet suppress most messages
206
--help display this help and exit
207
--version output version information and exit
209
Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE")
210
or send email to <xml-i18n-tools\@gnome.org>.
216
## Sub for printing error messages
219
print STDERR "Try `${PROGRAM} --help' for more information.\n";
226
print "Merging translations into $OUTFILE.\n" unless $QUIET_ARG;
237
&get_translation_database;
240
# General-purpose code for looking up translations in .po files
245
$tmp =~ s/^.*\/(.*)\.po$/$1/;
251
for my $po_file (glob "$PO_DIR/*.po") {
252
$po_files_by_lang{po_file2lang($po_file)} = $po_file;
256
sub get_local_charset
259
my $alias_file = $ENV{"G_CHARSET_ALIAS"} || "/usr/lib/charset.alias";
261
# seek character encoding aliases in charset.alias (glib)
263
if (open CHARSET_ALIAS, $alias_file)
265
while (<CHARSET_ALIAS>)
268
return $1 if (/^\s*([-._a-zA-Z0-9]+)\s+$encoding\b/i)
274
# if not found, return input string
281
my ($in_po_file) = @_;
284
open IN_PO_FILE, $in_po_file or die;
287
## example: "Content-Type: text/plain; charset=ISO-8859-1\n"
288
if (/Content-Type\:.*charset=([-a-zA-Z0-9]+)\\n/)
298
print STDERR "Warning: no encoding found in $in_po_file. Assuming ISO-8859-1\n" unless $QUIET_ARG;
299
$encoding = "ISO-8859-1";
302
system ("$iconv -f $encoding -t UTF-8 </dev/null 2>/dev/null");
304
$encoding = get_local_charset($encoding);
310
sub utf8_sanity_check
312
print STDERR "Warning: option --pass-through has been removed.\n" if $PASS_THROUGH_ARG;
316
sub get_translation_database
319
&get_cached_translation_database;
321
&create_translation_database;
325
sub get_newest_po_age
329
foreach my $file (values %po_files_by_lang)
331
my $file_age = -M $file;
332
$newest_age = $file_age if !$newest_age || $file_age < $newest_age;
335
$newest_age = 0 if !$newest_age;
342
print "Generating and caching the translation database\n" unless $QUIET_ARG;
344
&create_translation_database;
346
open CACHE, ">$cache_file" || die;
347
print CACHE join "\x01", %translations;
353
print "Found cached translation database\n" unless $QUIET_ARG;
356
open CACHE, "<$cache_file" || die;
362
%translations = split "\x01", $contents;
365
sub get_cached_translation_database
367
my $cache_file_age = -M $cache_file;
368
if (defined $cache_file_age)
370
if ($cache_file_age <= &get_newest_po_age)
375
print "Found too-old cached translation database\n" unless $QUIET_ARG;
381
sub create_translation_database
383
for my $lang (keys %po_files_by_lang)
385
my $po_file = $po_files_by_lang{$lang};
389
my $encoding = get_po_encoding ($po_file);
391
if (lc $encoding eq "utf-8")
393
open PO_FILE, "<$po_file";
397
print STDERR "WARNING: $po_file is not in UTF-8 but $encoding, converting...\n" unless $QUIET_ARG;;
399
open PO_FILE, "$iconv -f $encoding -t UTF-8 $po_file|";
404
open PO_FILE, "<$po_file";
415
$nextfuzzy = 1 if /^#, fuzzy/;
417
if (/^msgid "((\\.|[^\\])*)"/ )
419
$translations{$lang, $msgid} = $msgstr if $inmsgstr && $msgid && $msgstr;
426
$msgid = unescape_po_string($1);
433
if (/^msgstr "((\\.|[^\\])*)"/)
435
$msgstr = unescape_po_string($1);
440
if (/^"((\\.|[^\\])*)"/)
442
$msgid .= unescape_po_string($1) if $inmsgid;
443
$msgstr .= unescape_po_string($1) if $inmsgstr;
446
$translations{$lang, $msgid} = $msgstr if $inmsgstr && $msgid && $msgstr;
454
sub unescape_one_sequence
458
return "\\" if $sequence eq "\\\\";
459
return "\"" if $sequence eq "\\\"";
460
return "\n" if $sequence eq "\\n";
461
return "\r" if $sequence eq "\\r";
462
return "\t" if $sequence eq "\\t";
463
return "\b" if $sequence eq "\\b";
464
return "\f" if $sequence eq "\\f";
465
return "\a" if $sequence eq "\\a";
466
return chr(11) if $sequence eq "\\v"; # vertical tab, see ascii(7)
468
return chr(hex($1)) if ($sequence =~ /\\x([0-9a-fA-F]{2})/);
469
return chr(oct($1)) if ($sequence =~ /\\([0-7]{3})/);
471
# FIXME: Is \0 supported as well? Kenneth and Rodney don't want it, see bug #48489
476
sub unescape_po_string
480
$string =~ s/(\\x[0-9a-fA-F]{2}|\\[0-7]{3}|\\.)/unescape_one_sequence($1)/eg;
485
## NOTE: deal with < - < but not > - > because it seems its ok to have
486
## > in the entity. For further info please look at #84738.
499
# entity_encode: (string)
501
# Encode the given string to XML format (encode '<' etc).
505
my ($pre_encoded) = @_;
507
my @list_of_chars = unpack ('C*', $pre_encoded);
509
# with UTF-8 we only encode minimalistic
510
return join ('', map (&entity_encode_int_minimalist, @list_of_chars));
513
sub entity_encode_int_minimalist
515
return """ if $_ == 34;
516
return "&" if $_ == 38;
517
return "'" if $_ == 39;
518
return "<" if $_ == 60;
522
sub entity_encoded_translation
524
my ($lang, $string) = @_;
526
my $translation = $translations{$lang, $string};
527
return $string if !$translation;
528
return entity_encode ($translation);
531
## XML (bonobo-activation specific) merge code
533
sub ba_merge_translations
538
local $/; # slurp mode
539
open INPUT, "<$FILE" or die "can't open $FILE: $!";
544
open OUTPUT, ">$OUTFILE" or die "can't open $OUTFILE: $!";
546
while ($source =~ s|^(.*?)([ \t]*<\s*$w+\s+($w+\s*=\s*"$q"\s*)+/?>)([ \t]*\n)?||s)
550
my $node = $2 . "\n";
554
while (s/(\s)_($w+\s*=\s*"($q)")/$1$2/s) {
555
push @strings, entity_decode($3);
560
for my $string (@strings)
562
for my $lang (keys %po_files_by_lang)
564
$langs{$lang} = 1 if $translations{$lang, $string};
568
for my $lang (sort keys %langs)
571
s/(\sname\s*=\s*)"($q)"/$1"$2-$lang"/s;
572
s/(\s)_($w+\s*=\s*")($q)"/$1 . $2 . entity_encoded_translation($lang, $3) . '"'/seg;
577
print OUTPUT $source;
583
## XML (non-bonobo-activation) merge code
586
# Process tag attributes
587
# Only parameter is a HASH containing attributes -> values mapping
588
sub getAttributeString
591
my $do_translate = shift || 0;
592
my $language = shift || "";
594
my $translate = shift;
595
foreach my $e (reverse(sort(keys %{ $sub }))) {
597
my $string = $sub->{$e};
600
$string =~ s/^[\s]+//;
601
$string =~ s/[\s]+$//;
603
if ($string =~ /^'.*'$/)
607
$string =~ s/^['"]//g;
608
$string =~ s/['"]$//g;
610
if ($do_translate && $key =~ /^_/) {
616
my $decode_string = entity_decode($string);
617
my $translation = $translations{$language, $decode_string};
619
$translation = entity_encode($translation);
620
$string = $translation;
624
$$translate = 1 if ($translate && (!$$translate)); # watch not to "overwrite" if $translate == 2
628
$result .= " $key=$quote$string$quote";
633
# Returns a translatable string from XML node, it works on contents of every node in XML::Parser tree
634
# doesn't support nesting of translatable tags (i.e. <_blah>this <_doh>doesn't</_doh> work</_blah> -- besides
635
# can you define the correct semantics for this?)
641
my @list = @{ $ref };
644
my $count = scalar(@list);
645
my $attrs = $list[0];
648
while ($index < $count) {
649
my $type = $list[$index];
650
my $content = $list[$index+1];
654
# lets strip the whitespace here, and *ONLY* here
655
$content =~ s/\s+/ /gs if (!((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/)));
656
$result .= ($content);
658
#print "no cdata content when expected it\n"; # is this possible, is this ok?
659
# what to do if this happens?
660
# Did I mention that I hate XML::Parser tree style?
663
# We've got another element
665
$result .= getAttributeString(@{$content}[0], 0); # no nested translatable elements
667
my $subresult = getXMLstring($content);
669
$result .= ">".$subresult . "</$type>";
685
my $nodename = shift;
687
my $language = shift || "";
690
if ($content =~ /^[\s]*$/) {
691
$leading_space .= $content;
696
my @all = @{ $content };
697
my $attrs = shift @all;
699
my $outattr = getAttributeString($attrs, 1, $language, \$translate);
701
if ($nodename =~ /^_/) {
706
print $fh "<$nodename", $outattr;
708
$lookup = getXMLstring($content);
709
if (!((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/))) {
710
$lookup =~ s/^\s+//s;
711
$lookup =~ s/\s+$//s;
714
if ($lookup || $translate == 2) {
715
my $translation = $translations{$language, $lookup};
716
if ($MULTIPLE_OUTPUT && ($translation || $translate == 2)) {
717
$translation = $lookup if (!$translation);
718
print $fh " xml:lang=\"", $language, "\"";
719
print $fh ">", $translation, "</$nodename>";
720
return; # this means there will be no same translation with xml:lang="$language"...
721
# if we want them both, just remove this "return"
723
print $fh ">$lookup</$nodename>";
729
for my $lang (sort keys %po_files_by_lang) {
730
if ($MULTIPLE_OUTPUT && $lang ne "$language") {
737
my $localattrs = getAttributeString($attrs, 1, $lang, \$translate);
738
my $translation = $translations{$lang, $lookup};
739
if ($translate && !$translation) {
740
$translation = $lookup;
743
if ($translation || $translate) {
744
$translation = ($translation);
746
$leading_space =~ s/.*\n//g;
747
print $fh $leading_space;
748
print $fh "<", $nodename, " xml:lang=\"", $lang, "\"", $localattrs;
749
print $fh ">", $translation , "</$nodename>";
755
my $count = scalar(@all);
762
while ($index < $count) {
763
my $type = $all[$index];
764
my $rest = $all[$index+1];
765
traverse($fh, $type, $rest, $language);
769
print $fh "</$nodename>";
775
sub intltool_tree_char
779
my $clist = $expat->{Curlist};
782
# Use original_string so that we retain escaped entities
785
if ($pos > 0 and $clist->[$pos - 1] eq '0') {
786
$clist->[$pos] .= $expat->original_string();
788
push @$clist, 0 => $expat->original_string();
792
sub intltool_tree_start
798
# Use original_string so that we retain escaped entities
799
# in attribute values. We must convert the string to an
800
# @origlist array to conform to the structure of the Tree
803
my @original_array = split /\x/, $expat->original_string();
804
my $source = $expat->original_string();
806
# Remove leading tag.
808
$source =~ s|^\s*<\s*(\S+)||s;
810
# Grab attribute key/value pairs and push onto @origlist array.
814
if ($source =~ /^\s*([\w:-]+)\s*[=]\s*["]/)
816
$source =~ s|^\s*([\w:-]+)\s*[=]\s*["]([^"]*)["]||s;
818
push @origlist, '"' . $2 . '"';
820
elsif ($source =~ /^\s*([\w:-]+)\s*[=]\s*[']/)
822
$source =~ s|^\s*([\w:-]+)\s*[=]\s*[']([^']*)[']||s;
824
push @origlist, "'" . $2 . "'";
832
my $ol = [ { @origlist } ];
834
push @{ $expat->{Lists} }, $expat->{Curlist};
835
push @{ $expat->{Curlist} }, $tag => $ol;
836
$expat->{Curlist} = $ol;
841
my $filename = shift || return;
843
die "ERROR Cannot find filename: $filename\n";
846
my $ret = eval 'require XML::Parser';
848
die "You must have XML::Parser installed to run $0\n\n";
850
my $xp = new XML::Parser(Style => 'Tree');
851
$xp->setHandlers(Char => \&intltool_tree_char);
852
$xp->setHandlers(Start => \&intltool_tree_start);
853
my $tree = $xp->parsefile($filename);
855
# <foo><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo>
857
# [foo, [{}, head, [{id => "a"}, 0, "Hello ", em, [{}, 0, "there"]], bar, [{},
858
# 0, "Howdy", ref, [{}]], 0, "do" ] ]
870
die "ERROR Cannot find filename: $infile\n";
873
print $fh qq{<?xml version="1.0" encoding="UTF-8"?>\n};
876
open DOCINPUT, "<${FILE}" or die;
877
$source = <DOCINPUT>;
880
if ($source =~ /(<!DOCTYPE.*\[.*\]\s*>)/s)
884
elsif ($source =~ /(<!DOCTYPE[^>]*>)/s)
894
my $language = shift || "";
896
my $name = shift @{ $ref };
897
my $cont = shift @{ $ref };
898
traverse($fh, $name, $cont, $language);
905
if ($MULTIPLE_OUTPUT) {
906
for my $lang (sort keys %po_files_by_lang) {
908
mkdir $lang or die "Cannot create subdirectory $lang: $!\n";
910
open OUTPUT, ">$lang/$OUTFILE" or die "Cannot open $lang/$OUTFILE: $!\n";
911
my $tree = readXml($FILE);
912
print_header($FILE, \*OUTPUT);
913
parseTree(\*OUTPUT, $tree, $lang);
915
print "CREATED $lang/$OUTFILE\n" unless $QUIET_ARG;
918
open OUTPUT, ">$OUTFILE" or die "Cannot open $OUTFILE: $!\n";
919
my $tree = readXml($FILE);
920
print_header($FILE, \*OUTPUT);
921
parseTree(\*OUTPUT, $tree);
923
print "CREATED $OUTFILE\n" unless $QUIET_ARG;
926
sub keys_merge_translations
928
open INPUT, "<${FILE}" or die;
929
open OUTPUT, ">${OUTFILE}" or die;
933
if (s/^(\s*)_(\w+=(.*))/$1$2/)
939
my $non_translated_line = $_;
941
for my $lang (sort keys %po_files_by_lang)
943
my $translation = $translations{$lang, $string};
944
next if !$translation;
946
$_ = $non_translated_line;
947
s/(\w+)=.*/[$lang]$1=$translation/;
961
sub desktop_merge_translations
963
open INPUT, "<${FILE}" or die;
964
open OUTPUT, ">${OUTFILE}" or die;
968
if (s/^(\s*)_(\w+=(.*))/$1$2/)
974
my $non_translated_line = $_;
976
for my $lang (sort keys %po_files_by_lang)
978
my $translation = $translations{$lang, $string};
979
next if !$translation;
981
$_ = $non_translated_line;
982
s/(\w+)=.*/${1}[$lang]=$translation/;
996
sub schemas_merge_translations
1001
local $/; # slurp mode
1002
open INPUT, "<$FILE" or die "can't open $FILE: $!";
1007
open OUTPUT, ">$OUTFILE" or die;
1009
# FIXME: support attribute translations
1011
# Empty nodes never need translation, so unmark all of them.
1012
# For example, <_foo/> is just replaced by <foo/>.
1013
$source =~ s|<\s*_($w+)\s*/>|<$1/>|g;
1015
while ($source =~ s/
1017
(\s+)(<locale\ name="C">(\s*)
1018
(<default>\s*(?:<!--[^>]*?-->\s*)?(.*?)\s*<\/default>)?(\s*)
1019
(<short>\s*(?:<!--[^>]*?-->\s*)?(.*?)\s*<\/short>)?(\s*)
1020
(<long>\s*(?:<!--[^>]*?-->\s*)?(.*?)\s*<\/long>)?(\s*)
1026
my $locale_start_spaces = $2 ? $2 : '';
1027
my $default_spaces = $4 ? $4 : '';
1028
my $short_spaces = $7 ? $7 : '';
1029
my $long_spaces = $10 ? $10 : '';
1030
my $locale_end_spaces = $13 ? $13 : '';
1031
my $c_default_block = $3 ? $3 : '';
1032
my $default_string = $6 ? $6 : '';
1033
my $short_string = $9 ? $9 : '';
1034
my $long_string = $12 ? $12 : '';
1036
print OUTPUT "$locale_start_spaces$c_default_block";
1038
$default_string =~ s/\s+/ /g;
1039
$default_string = entity_decode($default_string);
1040
$short_string =~ s/\s+/ /g;
1041
$short_string = entity_decode($short_string);
1042
$long_string =~ s/\s+/ /g;
1043
$long_string = entity_decode($long_string);
1045
for my $lang (sort keys %po_files_by_lang)
1047
my $default_translation = $translations{$lang, $default_string};
1048
my $short_translation = $translations{$lang, $short_string};
1049
my $long_translation = $translations{$lang, $long_string};
1051
next if (!$default_translation && !$short_translation &&
1052
!$long_translation);
1054
print OUTPUT "\n$locale_start_spaces<locale name=\"$lang\">";
1056
print OUTPUT "$default_spaces";
1058
if ($default_translation)
1060
$default_translation = entity_encode($default_translation);
1061
print OUTPUT "<default>$default_translation</default>";
1064
print OUTPUT "$short_spaces";
1066
if ($short_translation)
1068
$short_translation = entity_encode($short_translation);
1069
print OUTPUT "<short>$short_translation</short>";
1072
print OUTPUT "$long_spaces";
1074
if ($long_translation)
1076
$long_translation = entity_encode($long_translation);
1077
print OUTPUT "<long>$long_translation</long>";
1080
print OUTPUT "$locale_end_spaces</locale>";
1084
print OUTPUT $source;
1089
sub rfc822deb_merge_translations
1092
for my $lang (keys %po_files_by_lang) {
1093
$encodings{$lang} = ($UTF8_ARG ? 'UTF-8' : get_po_encoding($po_files_by_lang{$lang}));
1098
$Text::Wrap::huge = 'overflow';
1099
$Text::Wrap::break = qr/\n|\s(?=\S)/;
1102
local $/; # slurp mode
1103
open INPUT, "<$FILE" or die "can't open $FILE: $!";
1108
open OUTPUT, ">${OUTFILE}" or die;
1110
while ($source =~ /(^|\n+)(_*)([^:\s]+)(:[ \t]*)(.*?)(?=\n[\S\n]|$)/sg)
1113
my $non_translated_line = $3.$4;
1115
my $underscore = length($2);
1116
next if $underscore eq 0 && $non_translated_line =~ /^#/;
1117
# Remove [] dummy strings
1118
my $stripped = $string;
1119
$stripped =~ s/\[\s[^\[\]]*\],/,/g if $underscore eq 2;
1120
$stripped =~ s/\[\s[^\[\]]*\]$//;
1121
$non_translated_line .= $stripped;
1123
print OUTPUT $sep.$non_translated_line;
1127
my @str_list = rfc822deb_split($underscore, $string);
1129
for my $lang (sort keys %po_files_by_lang)
1131
my $is_translated = 1;
1132
my $str_translated = '';
1135
for my $str (@str_list)
1137
my $translation = $translations{$lang, $str};
1145
# $translation may also contain [] dummy
1146
# strings, mostly to indicate an empty string
1147
$translation =~ s/\[\s[^\[\]]*\]$//;
1151
if ($underscore eq 2)
1153
$str_translated .= $translation;
1158
Text::Tabs::expand($translation) .
1164
if ($underscore eq 2)
1166
$str_translated .= ', ' . $translation;
1170
$str_translated .= Text::Tabs::expand(
1171
Text::Wrap::wrap(' ', ' ', $translation)) .
1177
# To fix some problems with Text::Wrap::wrap
1178
$str_translated =~ s/(\n )+\n/\n .\n/g;
1180
next unless $is_translated;
1182
$str_translated =~ s/\n \.\n$//;
1183
$str_translated =~ s/\s+$//;
1185
$_ = $non_translated_line;
1186
s/^(\w+):\s*.*/$sep${1}-$lang.$encodings{$lang}: $str_translated/s;
1199
# Debian defines a special way to deal with rfc822-style files:
1200
# when a value contain newlines, it consists of
1201
# 1. a short form (first line)
1202
# 2. a long description, all lines begin with a space,
1203
# and paragraphs are separated by a single dot on a line
1204
# This routine returns an array of all paragraphs, and reformat
1206
# When first argument is 2, the string is a comma separated list of
1210
$text =~ s/^[ \t]//mg;
1211
return (split(/, */, $text, 0)) if $type ne 1;
1212
return ($text) if $text !~ /\n/;
1214
$text =~ s/([^\n]*)\n//;
1218
for my $line (split (/\n/, $text))
1221
if ($line =~ /^\.\s*$/)
1228
elsif ($line =~ /^\s/)
1230
# Line which must not be reformatted
1231
$str .= "\n" if length ($str) && $str !~ /\n$/;
1237
# Continuation line, remove newline
1238
$str .= " " if length ($str) && $str !~ /\n$/;
1244
push(@list, $str) if length ($str);