Save the plural information given in po files
This commit is contained in:
parent
fb97600091
commit
e064e53aa3
25
l10n/l10n.pl
25
l10n/l10n.pl
|
@ -64,6 +64,16 @@ sub readIgnorelist{
|
||||||
return %ignore;
|
return %ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub getPluralInfo {
|
||||||
|
my( $info ) = @_;
|
||||||
|
|
||||||
|
# get string
|
||||||
|
$info =~ s/.*Plural-Forms: (.+)\\n.*/$1/;
|
||||||
|
$info =~ s/^(.*)\\n.*/$1/g;
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
my $task = shift( @ARGV );
|
my $task = shift( @ARGV );
|
||||||
my $place = '..';
|
my $place = '..';
|
||||||
|
|
||||||
|
@ -132,11 +142,15 @@ elsif( $task eq 'write' ){
|
||||||
my $array = Locale::PO->load_file_asarray( $input );
|
my $array = Locale::PO->load_file_asarray( $input );
|
||||||
# Create array
|
# Create array
|
||||||
my @strings = ();
|
my @strings = ();
|
||||||
foreach my $string ( @{$array} ){
|
my $plurals;
|
||||||
next if $string->msgid() eq '""';
|
|
||||||
|
|
||||||
# Do we use singular or plural?
|
foreach my $string ( @{$array} ){
|
||||||
if( defined( $string->msgstr_n() )){
|
if( $string->msgid() eq '""' ){
|
||||||
|
# Translator information
|
||||||
|
$plurals = getPluralInfo( $string->msgstr());
|
||||||
|
}
|
||||||
|
elsif( defined( $string->msgstr_n() )){
|
||||||
|
# plural translations
|
||||||
my @variants = ();
|
my @variants = ();
|
||||||
my $identifier = $string->msgid()."::".$string->msgid_plural();
|
my $identifier = $string->msgid()."::".$string->msgid_plural();
|
||||||
$identifier =~ s/"/_/g;
|
$identifier =~ s/"/_/g;
|
||||||
|
@ -148,6 +162,7 @@ elsif( $task eq 'write' ){
|
||||||
push( @strings, "\"$identifier\" => array(".join(@variants, ",").")");
|
push( @strings, "\"$identifier\" => array(".join(@variants, ",").")");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
# singular translations
|
||||||
next if $string->msgstr() eq '""';
|
next if $string->msgstr() eq '""';
|
||||||
push( @strings, $string->msgid()." => ".$string->msgstr());
|
push( @strings, $string->msgid()." => ".$string->msgstr());
|
||||||
}
|
}
|
||||||
|
@ -158,7 +173,7 @@ elsif( $task eq 'write' ){
|
||||||
open( OUT, ">$language.php" );
|
open( OUT, ">$language.php" );
|
||||||
print OUT "<?php \$TRANSLATIONS = array(\n";
|
print OUT "<?php \$TRANSLATIONS = array(\n";
|
||||||
print OUT join( ",\n", @strings );
|
print OUT join( ",\n", @strings );
|
||||||
print OUT "\n);\n";
|
print OUT "\n); \$PLURAL_FORMS = \"$plurals\";\n";
|
||||||
close( OUT );
|
close( OUT );
|
||||||
}
|
}
|
||||||
chdir( $whereami );
|
chdir( $whereami );
|
||||||
|
|
Loading…
Reference in New Issue