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.31.2";
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{"INTLTOOL_ICONV"} || "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)
116
&ba_merge_translations;
119
elsif ($XML_STYLE_ARG && @ARGV > 2)
129
elsif ($KEYS_STYLE_ARG && @ARGV > 2)
134
&keys_merge_translations;
137
elsif ($DESKTOP_STYLE_ARG && @ARGV > 2)
141
&desktop_merge_translations;
144
elsif ($SCHEMAS_STYLE_ARG && @ARGV > 2)
148
&schemas_merge_translations;
151
elsif ($RFC822DEB_STYLE_ARG && @ARGV > 2)
155
&rfc822deb_merge_translations;
165
## Sub for printing release information
169
${PROGRAM} (${PACKAGE}) ${VERSION}
170
Written by Maciej Stachowiak, Darin Adler and Kenneth Christiansen.
172
Copyright (C) 2000-2003 Free Software Foundation, Inc.
173
Copyright (C) 2000-2001 Eazel, Inc.
174
This is free software; see the source for copying conditions. There is NO
175
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
180
## Sub for printing usage information
184
Usage: ${PROGRAM} [OPTION]... PO_DIRECTORY FILENAME OUTPUT_FILE
185
Generates an output file that includes some localized attributes from an
186
untranslated source file.
188
Mandatory options: (exactly one must be specified)
189
-b, --ba-style includes translations in the bonobo-activation style
190
-d, --desktop-style includes translations in the desktop style
191
-k, --keys-style includes translations in the keys style
192
-s, --schemas-style includes translations in the schemas style
193
-r, --rfc822deb-style includes translations in the RFC822 style
194
-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)
200
-m, --multiple-output output one localized file per locale, instead of
201
a single file containing all localized elements
202
-c, --cache=FILE specify cache file name
203
(usually \$top_builddir/po/.intltool-merge-cache)
204
-q, --quiet suppress most messages
205
--help display this help and exit
206
--version output version information and exit
208
Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE")
209
or send email to <xml-i18n-tools\@gnome.org>.
215
## Sub for printing error messages
218
print STDERR "Try `${PROGRAM} --help' for more information.\n";
225
print "Merging translations into $OUTFILE.\n" unless $QUIET_ARG;
236
&get_translation_database;
239
# General-purpose code for looking up translations in .po files
244
$tmp =~ s/^.*\/(.*)\.po$/$1/;
250
for my $po_file (glob "$PO_DIR/*.po") {
251
$po_files_by_lang{po_file2lang($po_file)} = $po_file;
255
sub get_local_charset
258
my $alias_file = $ENV{"G_CHARSET_ALIAS"} || "/home/carlos/gnome-cvs/lib/charset.alias";
260
# seek character encoding aliases in charset.alias (glib)
262
if (open CHARSET_ALIAS, $alias_file)
264
while (<CHARSET_ALIAS>)
267
return $1 if (/^\s*([-._a-zA-Z0-9]+)\s+$encoding\b/i)
273
# if not found, return input string
280
my ($in_po_file) = @_;
283
open IN_PO_FILE, $in_po_file or die;
286
## example: "Content-Type: text/plain; charset=ISO-8859-1\n"
287
if (/Content-Type\:.*charset=([-a-zA-Z0-9]+)\\n/)
297
print STDERR "Warning: no encoding found in $in_po_file. Assuming ISO-8859-1\n" unless $QUIET_ARG;
298
$encoding = "ISO-8859-1";
301
system ("$iconv -f $encoding -t UTF-8 </dev/null 2>/dev/null");
303
$encoding = get_local_charset($encoding);
309
sub utf8_sanity_check
313
if (!$PASS_THROUGH_ARG)
315
$PASS_THROUGH_ARG="1";
320
sub get_translation_database
323
&get_cached_translation_database;
325
&create_translation_database;
329
sub get_newest_po_age
333
foreach my $file (values %po_files_by_lang)
335
my $file_age = -M $file;
336
$newest_age = $file_age if !$newest_age || $file_age < $newest_age;
339
$newest_age = 0 if !$newest_age;
346
print "Generating and caching the translation database\n" unless $QUIET_ARG;
348
&create_translation_database;
350
open CACHE, ">$cache_file" || die;
351
print CACHE join "\x01", %translations;
357
print "Found cached translation database\n" unless $QUIET_ARG;
360
open CACHE, "<$cache_file" || die;
366
%translations = split "\x01", $contents;
369
sub get_cached_translation_database
371
my $cache_file_age = -M $cache_file;
372
if (defined $cache_file_age)
374
if ($cache_file_age <= &get_newest_po_age)
379
print "Found too-old cached translation database\n" unless $QUIET_ARG;
385
sub create_translation_database
387
for my $lang (keys %po_files_by_lang)
389
my $po_file = $po_files_by_lang{$lang};
393
my $encoding = get_po_encoding ($po_file);
395
if (lc $encoding eq "utf-8")
397
open PO_FILE, "<$po_file";
401
print STDERR "WARNING: $po_file is not in UTF-8 but $encoding, converting...\n" unless $QUIET_ARG;;
403
open PO_FILE, "$iconv -f $encoding -t UTF-8 $po_file|";
408
open PO_FILE, "<$po_file";
419
$nextfuzzy = 1 if /^#, fuzzy/;
421
if (/^msgid "((\\.|[^\\])*)"/ )
423
$translations{$lang, $msgid} = $msgstr if $inmsgstr && $msgid && $msgstr;
430
$msgid = unescape_po_string($1);
437
if (/^msgstr "((\\.|[^\\])*)"/)
439
$msgstr = unescape_po_string($1);
444
if (/^"((\\.|[^\\])*)"/)
446
$msgid .= unescape_po_string($1) if $inmsgid;
447
$msgstr .= unescape_po_string($1) if $inmsgstr;
450
$translations{$lang, $msgid} = $msgstr if $inmsgstr && $msgid && $msgstr;
458
sub unescape_one_sequence
462
return "\\" if $sequence eq "\\\\";
463
return "\"" if $sequence eq "\\\"";
464
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.
472
sub unescape_po_string
476
$string =~ s/(\\.)/unescape_one_sequence($1)/eg;
481
## NOTE: deal with < - < but not > - > because it seems its ok to have
482
## > in the entity. For further info please look at #84738.
495
# entity_encode: (string)
497
# Encode the given string to XML format (encode '<' etc). It also
498
# encodes high bit if not in UTF-8 mode.
502
my ($pre_encoded) = @_;
504
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));
517
sub entity_encode_int_minimalist
519
return """ if $_ == 34;
520
return "&" if $_ == 38;
521
return "'" if $_ == 39;
522
return "<" if $_ == 60;
526
sub entity_encode_int_even_high_bit
528
if ($_ > 127 || $_ == 34 || $_ == 38 || $_ == 39 || $_ == 60)
530
# the ($_ > 127) should probably be removed
531
return "&#" . $_ . ";";
539
sub entity_encoded_translation
541
my ($lang, $string) = @_;
543
my $translation = $translations{$lang, $string};
544
return $string if !$translation;
545
return entity_encode ($translation);
548
## XML (bonobo-activation specific) merge code
550
sub ba_merge_translations
555
local $/; # slurp mode
556
open INPUT, "<$FILE" or die "can't open $FILE: $!";
561
open OUTPUT, ">$OUTFILE" or die "can't open $OUTFILE: $!";
563
while ($source =~ s|^(.*?)([ \t]*<\s*$w+\s+($w+\s*=\s*"$q"\s*)+/?>)([ \t]*\n)?||s)
567
my $node = $2 . "\n";
571
while (s/(\s)_($w+\s*=\s*"($q)")/$1$2/s) {
572
push @strings, entity_decode($3);
577
for my $string (@strings)
579
for my $lang (keys %po_files_by_lang)
581
$langs{$lang} = 1 if $translations{$lang, $string};
585
for my $lang (sort keys %langs)
588
s/(\sname\s*=\s*)"($q)"/$1"$2-$lang"/s;
589
s/(\s)_($w+\s*=\s*")($q)"/$1 . $2 . entity_encoded_translation($lang, $3) . '"'/seg;
594
print OUTPUT $source;
600
## XML (non-bonobo-activation) merge code
603
# Process tag attributes
604
# Only parameter is a HASH containing attributes -> values mapping
605
sub getAttributeString
608
my $do_translate = shift || 0;
609
my $language = shift || "";
611
foreach my $e (reverse(sort(keys %{ $sub }))) {
613
my $string = $sub->{$e};
616
$string =~ s/^[\s]+//;
617
$string =~ s/[\s]+$//;
619
if ($string =~ /^'.*'$/)
623
$string =~ s/^['"]//g;
624
$string =~ s/['"]$//g;
626
if ($do_translate && $key =~ /^_/) {
632
my $decode_string = entity_decode($string);
633
my $translation = $translations{$language, $decode_string};
635
$translation = entity_encode($translation);
636
$string = $translation;
641
$result .= " $key=$quote$string$quote";
646
# 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?)
654
my @list = @{ $ref };
657
my $count = scalar(@list);
658
my $attrs = $list[0];
660
while ($index < $count) {
661
my $type = $list[$index];
662
my $content = $list[$index+1];
666
# 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?
675
# We've got another element
677
$result .= getAttributeString($attrs, 0); # no nested translatable elements
679
my $subresult = getXMLstring($content);
681
$result .= ">".$subresult . "</$type>";
697
my $nodename = shift;
699
my $language = shift || "";
702
if ($content =~ /^[\s]*$/) {
703
$leading_space .= $content;
708
my @all = @{ $content };
709
my $attrs = shift @all;
710
my $outattr = getAttributeString($attrs, 1, $language);
713
if ($nodename =~ /^_/) {
718
print $fh "<$nodename$outattr";
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>";
729
return; # this means there will be no same translation with xml:lang="$language"...
730
# if we want them both, just remove this "return"
732
print $fh ">$lookup</$nodename>";
739
for my $lang (sort keys %po_files_by_lang) {
740
if ($MULTIPLE_OUTPUT && $lang ne "$language") {
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);
753
$leading_space =~ s/.*\n//g;
754
print $fh $leading_space;
755
print $fh "<", $nodename, " xml:lang=\"", $lang, "\"", $localattrs;
756
print $fh ">", $translation , "</$nodename>";
762
my $count = scalar(@all);
769
while ($index < $count) {
770
my $type = $all[$index];
771
my $rest = $all[$index+1];
772
traverse($fh, $type, $rest, $language);
776
print $fh "</$nodename>";
782
sub intltool_tree_char
786
my $clist = $expat->{Curlist};
789
# Use original_string so that we retain escaped entities
792
if ($pos > 0 and $clist->[$pos - 1] eq '0') {
793
$clist->[$pos] .= $expat->original_string();
795
push @$clist, 0 => $expat->original_string();
799
sub intltool_tree_start
805
# Use original_string so that we retain escaped entities
806
# in attribute values. We must convert the string to an
807
# @origlist array to conform to the structure of the Tree
810
my @original_array = split /\x/, $expat->original_string();
811
my $source = $expat->original_string();
813
# Remove leading tag.
815
$source =~ s|^\s*<\s*(\S+)||s;
817
# Grab attribute key/value pairs and push onto @origlist array.
821
if ($source =~ /^\s*([\w:-]+)\s*[=]\s*["]/)
823
$source =~ s|^\s*([\w:-]+)\s*[=]\s*["]([^"]*)["]||s;
825
push @origlist, '"' . $2 . '"';
827
elsif ($source =~ /^\s*([\w:-]+)\s*[=]\s*[']/)
829
$source =~ s|^\s*([\w:-]+)\s*[=]\s*[']([^']*)[']||s;
831
push @origlist, "'" . $2 . "'";
839
my $ol = [ { @origlist } ];
841
push @{ $expat->{Lists} }, $expat->{Curlist};
842
push @{ $expat->{Curlist} }, $tag => $ol;
843
$expat->{Curlist} = $ol;
848
my $filename = shift || return;
850
die "ERROR Cannot find filename: $filename\n";
853
my $ret = eval 'require XML::Parser';
855
die "You must have XML::Parser installed to run $0\n\n";
857
my $xp = new XML::Parser(Style => 'Tree');
858
$xp->setHandlers(Char => \&intltool_tree_char);
859
$xp->setHandlers(Start => \&intltool_tree_start);
860
my $tree = $xp->parsefile($filename);
862
# <foo><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo>
864
# [foo, [{}, head, [{id => "a"}, 0, "Hello ", em, [{}, 0, "there"]], bar, [{},
865
# 0, "Howdy", ref, [{}]], 0, "do" ] ]
877
die "ERROR Cannot find filename: $infile\n";
880
print $fh qq{<?xml version="1.0" encoding="UTF-8"?>\n};
883
open DOCINPUT, "<${FILE}" or die;
884
$source = <DOCINPUT>;
887
if ($source =~ /(<!DOCTYPE.*\[.*\]\s*>)/s)
891
elsif ($source =~ /(<!DOCTYPE[^>]*>)/s)
901
my $language = shift || "";
903
my $name = shift @{ $ref };
904
my $cont = shift @{ $ref };
905
traverse($fh, $name, $cont, $language);
912
if ($MULTIPLE_OUTPUT) {
913
for my $lang (sort keys %po_files_by_lang) {
915
mkdir $lang or die "Cannot create subdirectory $lang: $!\n";
917
open OUTPUT, ">$lang/$OUTFILE" or die "Cannot open $lang/$OUTFILE: $!\n";
918
my $tree = readXml($FILE);
919
print_header($FILE, \*OUTPUT);
920
parseTree(\*OUTPUT, $tree, $lang);
922
print "CREATED $lang/$OUTFILE\n" unless $QUIET_ARG;
925
open OUTPUT, ">$OUTFILE" or die "Cannot open $OUTFILE: $!\n";
926
my $tree = readXml($FILE);
927
print_header($FILE, \*OUTPUT);
928
parseTree(\*OUTPUT, $tree);
930
print "CREATED $OUTFILE\n" unless $QUIET_ARG;
933
sub keys_merge_translations
935
open INPUT, "<${FILE}" or die;
936
open OUTPUT, ">${OUTFILE}" or die;
940
if (s/^(\s*)_(\w+=(.*))/$1$2/)
946
my $non_translated_line = $_;
948
for my $lang (sort keys %po_files_by_lang)
950
my $translation = $translations{$lang, $string};
951
next if !$translation;
953
$_ = $non_translated_line;
954
s/(\w+)=.*/[$lang]$1=$translation/;
968
sub desktop_merge_translations
970
open INPUT, "<${FILE}" or die;
971
open OUTPUT, ">${OUTFILE}" or die;
975
if (s/^(\s*)_(\w+=(.*))/$1$2/)
981
my $non_translated_line = $_;
983
for my $lang (sort keys %po_files_by_lang)
985
my $translation = $translations{$lang, $string};
986
next if !$translation;
988
$_ = $non_translated_line;
989
s/(\w+)=.*/${1}[$lang]=$translation/;
1003
sub schemas_merge_translations
1008
local $/; # slurp mode
1009
open INPUT, "<$FILE" or die "can't open $FILE: $!";
1014
open OUTPUT, ">$OUTFILE" or die;
1016
# FIXME: support attribute translations
1018
# Empty nodes never need translation, so unmark all of them.
1019
# For example, <_foo/> is just replaced by <foo/>.
1020
$source =~ s|<\s*_($w+)\s*/>|<$1/>|g;
1022
while ($source =~ s/
1024
(\s+)(<locale\ name="C">(\s*)
1025
(<default>\s*(?:<!--[^>]*?-->\s*)?(.*?)\s*<\/default>)?(\s*)
1026
(<short>\s*(?:<!--[^>]*?-->\s*)?(.*?)\s*<\/short>)?(\s*)
1027
(<long>\s*(?:<!--[^>]*?-->\s*)?(.*?)\s*<\/long>)?(\s*)
1033
my $locale_start_spaces = $2 ? $2 : '';
1034
my $default_spaces = $4 ? $4 : '';
1035
my $short_spaces = $7 ? $7 : '';
1036
my $long_spaces = $10 ? $10 : '';
1037
my $locale_end_spaces = $13 ? $13 : '';
1038
my $c_default_block = $3 ? $3 : '';
1039
my $default_string = $6 ? $6 : '';
1040
my $short_string = $9 ? $9 : '';
1041
my $long_string = $12 ? $12 : '';
1043
print OUTPUT "$locale_start_spaces$c_default_block";
1045
$default_string =~ s/\s+/ /g;
1046
$default_string = entity_decode($default_string);
1047
$short_string =~ s/\s+/ /g;
1048
$short_string = entity_decode($short_string);
1049
$long_string =~ s/\s+/ /g;
1050
$long_string = entity_decode($long_string);
1052
for my $lang (sort keys %po_files_by_lang)
1054
my $default_translation = $translations{$lang, $default_string};
1055
my $short_translation = $translations{$lang, $short_string};
1056
my $long_translation = $translations{$lang, $long_string};
1058
next if (!$default_translation && !$short_translation &&
1059
!$long_translation);
1061
print OUTPUT "\n$locale_start_spaces<locale name=\"$lang\">";
1063
print OUTPUT "$default_spaces";
1065
if ($default_translation)
1067
$default_translation = entity_encode($default_translation);
1068
print OUTPUT "<default>$default_translation</default>";
1071
print OUTPUT "$short_spaces";
1073
if ($short_translation)
1075
$short_translation = entity_encode($short_translation);
1076
print OUTPUT "<short>$short_translation</short>";
1079
print OUTPUT "$long_spaces";
1081
if ($long_translation)
1083
$long_translation = entity_encode($long_translation);
1084
print OUTPUT "<long>$long_translation</long>";
1087
print OUTPUT "$locale_end_spaces</locale>";
1091
print OUTPUT $source;
1096
sub rfc822deb_merge_translations
1099
for my $lang (keys %po_files_by_lang) {
1100
$encodings{$lang} = ($UTF8_ARG ? 'UTF-8' : get_po_encoding($po_files_by_lang{$lang}));
1105
$Text::Wrap::huge = 'overflow';
1106
$Text::Wrap::break = qr/\n|\s(?=\S)/;
1109
local $/; # slurp mode
1110
open INPUT, "<$FILE" or die "can't open $FILE: $!";
1115
open OUTPUT, ">${OUTFILE}" or die;
1117
while ($source =~ /(^|\n+)(_*)([^:\s]+)(:[ \t]*)(.*?)(?=\n[\S\n]|$)/sg)
1120
my $non_translated_line = $3.$4;
1122
my $underscore = length($2);
1123
next if $underscore eq 0 && $non_translated_line =~ /^#/;
1124
# Remove [] dummy strings
1125
my $stripped = $string;
1126
$stripped =~ s/\[\s[^\[\]]*\],/,/g if $underscore eq 2;
1127
$stripped =~ s/\[\s[^\[\]]*\]$//;
1128
$non_translated_line .= $stripped;
1130
print OUTPUT $sep.$non_translated_line;
1134
my @str_list = rfc822deb_split($underscore, $string);
1136
for my $lang (sort keys %po_files_by_lang)
1138
my $is_translated = 1;
1139
my $str_translated = '';
1142
for my $str (@str_list)
1144
my $translation = $translations{$lang, $str};
1152
# $translation may also contain [] dummy
1153
# strings, mostly to indicate an empty string
1154
$translation =~ s/\[\s[^\[\]]*\]$//;
1158
if ($underscore eq 2)
1160
$str_translated .= $translation;
1165
Text::Tabs::expand($translation) .
1171
if ($underscore eq 2)
1173
$str_translated .= ', ' . $translation;
1177
$str_translated .= Text::Tabs::expand(
1178
Text::Wrap::wrap(' ', ' ', $translation)) .
1184
# To fix some problems with Text::Wrap::wrap
1185
$str_translated =~ s/(\n )+\n/\n .\n/g;
1187
next unless $is_translated;
1189
$str_translated =~ s/\n \.\n$//;
1190
$str_translated =~ s/\s+$//;
1192
$_ = $non_translated_line;
1193
s/^(\w+):\s*.*/$sep${1}-$lang.$encodings{$lang}: $str_translated/s;
1206
# Debian defines a special way to deal with rfc822-style files:
1207
# when a value contain newlines, it consists of
1208
# 1. a short form (first line)
1209
# 2. a long description, all lines begin with a space,
1210
# and paragraphs are separated by a single dot on a line
1211
# This routine returns an array of all paragraphs, and reformat
1213
# When first argument is 2, the string is a comma separated list of
1217
$text =~ s/^[ \t]//mg;
1218
return (split(/, */, $text, 0)) if $type ne 1;
1219
return ($text) if $text !~ /\n/;
1221
$text =~ s/([^\n]*)\n//;
1225
for my $line (split (/\n/, $text))
1228
if ($line =~ /^\.\s*$/)
1235
elsif ($line =~ /^\s/)
1237
# Line which must not be reformatted
1238
$str .= "\n" if length ($str) && $str !~ /\n$/;
1244
# Continuation line, remove newline
1245
$str .= " " if length ($str) && $str !~ /\n$/;
1251
push(@list, $str) if length ($str);