diff options
Diffstat (limited to 'l10n/l10n.pl')
-rw-r--r-- | l10n/l10n.pl | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/l10n/l10n.pl b/l10n/l10n.pl index b07d6d686bc..2790ca92015 100644 --- a/l10n/l10n.pl +++ b/l10n/l10n.pl @@ -39,7 +39,7 @@ sub crawlFiles{ foreach my $i ( @files ){ next if substr( $i, 0, 1 ) eq '.'; next if $i eq 'l10n'; - + if( -d $dir.'/'.$i ){ push( @found, crawlFiles( $dir.'/'.$i )); } @@ -64,6 +64,16 @@ sub readIgnorelist{ 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 $place = '..'; @@ -100,11 +110,17 @@ if( $task eq 'read' ){ foreach my $file ( @totranslate ){ next if $ignore{$file}; - my $keyword = ( $file =~ /\.js$/ ? 't:2' : 't'); + my $keywords = ''; + if( $file =~ /\.js$/ ){ + $keywords = '--keyword=t:2 --keyword=n:2,3'; + } + else{ + $keywords = '--keyword=t --keyword=n:1,2'; + } my $language = ( $file =~ /\.js$/ ? 'Python' : 'PHP'); my $joinexisting = ( -e $output ? '--join-existing' : ''); print " Reading $file\n"; - `xgettext --output="$output" $joinexisting --keyword=$keyword --language=$language "$file" --from-code=UTF-8 --package-version="5.0.0" --package-name="ownCloud Core" --msgid-bugs-address="translations\@owncloud.org"`; + `xgettext --output="$output" $joinexisting $keywords --language=$language "$file" --from-code=UTF-8 --package-version="5.0.0" --package-name="ownCloud Core" --msgid-bugs-address="translations\@owncloud.org"`; } chdir( $whereami ); } @@ -118,7 +134,7 @@ elsif( $task eq 'write' ){ print " Processing $app\n"; foreach my $language ( @languages ){ next if $language eq 'templates'; - + my $input = "${whereami}/$language/$app.po"; next unless -e $input; @@ -126,18 +142,38 @@ elsif( $task eq 'write' ){ my $array = Locale::PO->load_file_asarray( $input ); # Create array my @strings = (); + my $plurals; + foreach my $string ( @{$array} ){ - next if $string->msgid() eq '""'; - next if $string->msgstr() eq '""'; - push( @strings, $string->msgid()." => ".$string->msgstr()); + if( $string->msgid() eq '""' ){ + # Translator information + $plurals = getPluralInfo( $string->msgstr()); + } + elsif( defined( $string->msgstr_n() )){ + # plural translations + my @variants = (); + my $identifier = $string->msgid()."::".$string->msgid_plural(); + $identifier =~ s/"/_/g; + + foreach my $variant ( sort { $a <=> $b} keys( %{$string->msgstr_n()} )){ + push( @variants, $string->msgstr_n()->{$variant} ); + } + + push( @strings, "\"$identifier\" => array(".join(@variants, ",").")"); + } + else{ + # singular translations + next if $string->msgstr() eq '""'; + push( @strings, $string->msgid()." => ".$string->msgstr()); + } } next if $#strings == -1; # Skip empty files # Write PHP file open( OUT, ">$language.php" ); - print OUT "<?php \$TRANSLATIONS = array(\n"; + print OUT "<?php\n\$TRANSLATIONS = array(\n"; print OUT join( ",\n", @strings ); - print OUT "\n);\n"; + print OUT "\n);\n\$PLURAL_FORMS = \"$plurals\";\n"; close( OUT ); } chdir( $whereami ); |