From e13d1d0cf2548c172e3c670ef7fe1b35befbb755 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Sun, 7 Jul 2013 19:51:24 +0200 Subject: Add possibility to read/write plural translations --- l10n/l10n.pl | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'l10n') diff --git a/l10n/l10n.pl b/l10n/l10n.pl index b07d6d686bc..8d13ec29a37 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 )); } @@ -100,11 +100,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=tp:2,3'; + } + else{ + $keywords = '--keyword=t --keyword=tp: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 +124,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; @@ -128,8 +134,18 @@ elsif( $task eq 'write' ){ my @strings = (); foreach my $string ( @{$array} ){ next if $string->msgid() eq '""'; - next if $string->msgstr() eq '""'; - push( @strings, $string->msgid()." => ".$string->msgstr()); + + # Do we use singular or plural? + if( defined( $string->msgstr_n() )){ + next if $string->msgstr_n()->{"0"} eq '""' || + $string->msgstr_n()->{"1"} eq '""'; + push( @strings, $string->msgid()." => ".$string->msgstr_n()->{"0"} ); + push( @strings, $string->msgid_plural()." => ".$string->msgstr_n()->{"1"} ); + } + else{ + next if $string->msgstr() eq '""'; + push( @strings, $string->msgid()." => ".$string->msgstr()); + } } next if $#strings == -1; # Skip empty files -- cgit v1.2.3 From 18fc22b52bdf1d8372a6e9c602872c423ce50eff Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Tue, 16 Jul 2013 21:38:31 +0200 Subject: Allow several plural forms in l10n php files --- l10n/l10n.pl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'l10n') diff --git a/l10n/l10n.pl b/l10n/l10n.pl index 8d13ec29a37..7694749dadf 100644 --- a/l10n/l10n.pl +++ b/l10n/l10n.pl @@ -102,10 +102,10 @@ if( $task eq 'read' ){ next if $ignore{$file}; my $keywords = ''; if( $file =~ /\.js$/ ){ - $keywords = '--keyword=t:2 --keyword=tp:2,3'; + $keywords = '--keyword=t:2 --keyword=n:2,3'; } else{ - $keywords = '--keyword=t --keyword=tp:1,2'; + $keywords = '--keyword=t --keyword=n:1,2'; } my $language = ( $file =~ /\.js$/ ? 'Python' : 'PHP'); my $joinexisting = ( -e $output ? '--join-existing' : ''); @@ -137,10 +137,15 @@ elsif( $task eq 'write' ){ # Do we use singular or plural? if( defined( $string->msgstr_n() )){ - next if $string->msgstr_n()->{"0"} eq '""' || - $string->msgstr_n()->{"1"} eq '""'; - push( @strings, $string->msgid()." => ".$string->msgstr_n()->{"0"} ); - push( @strings, $string->msgid_plural()." => ".$string->msgstr_n()->{"1"} ); + 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{ next if $string->msgstr() eq '""'; -- cgit v1.2.3 From 69b175dbf9979af05a51a3b1d7e349c53a2a6d9d Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Tue, 16 Jul 2013 22:25:19 +0200 Subject: Fix two bugs in l10n.pl --- l10n/l10n.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'l10n') diff --git a/l10n/l10n.pl b/l10n/l10n.pl index 7694749dadf..9e5caa6badb 100644 --- a/l10n/l10n.pl +++ b/l10n/l10n.pl @@ -138,14 +138,14 @@ elsif( $task eq 'write' ){ # Do we use singular or plural? if( defined( $string->msgstr_n() )){ my @variants = (); - my $identifier = $string->msgid()."::".$string->msgid_plural() + 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, ",").")"; + push( @strings, "\"$identifier\" => array(".join(@variants, ",").")"); } else{ next if $string->msgstr() eq '""'; -- cgit v1.2.3 From e064e53aa318bdfa43e62105e56f390f19a309f4 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Thu, 1 Aug 2013 19:13:52 +0200 Subject: Save the plural information given in po files --- l10n/l10n.pl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'l10n') diff --git a/l10n/l10n.pl b/l10n/l10n.pl index 9e5caa6badb..2a02e19c714 100644 --- a/l10n/l10n.pl +++ b/l10n/l10n.pl @@ -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 = '..'; @@ -132,11 +142,15 @@ elsif( $task eq 'write' ){ my $array = Locale::PO->load_file_asarray( $input ); # Create array my @strings = (); - foreach my $string ( @{$array} ){ - next if $string->msgid() eq '""'; + my $plurals; - # Do we use singular or plural? - if( defined( $string->msgstr_n() )){ + foreach my $string ( @{$array} ){ + 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; @@ -148,6 +162,7 @@ elsif( $task eq 'write' ){ push( @strings, "\"$identifier\" => array(".join(@variants, ",").")"); } else{ + # singular translations next if $string->msgstr() eq '""'; push( @strings, $string->msgid()." => ".$string->msgstr()); } @@ -158,7 +173,7 @@ elsif( $task eq 'write' ){ open( OUT, ">$language.php" ); print OUT " Date: Fri, 2 Aug 2013 21:45:36 +0200 Subject: add new line to generated php code --- l10n/l10n.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'l10n') diff --git a/l10n/l10n.pl b/l10n/l10n.pl index 2a02e19c714..e3a42aefe22 100644 --- a/l10n/l10n.pl +++ b/l10n/l10n.pl @@ -173,7 +173,7 @@ elsif( $task eq 'write' ){ open( OUT, ">$language.php" ); print OUT " Date: Fri, 2 Aug 2013 23:07:53 +0200 Subject: another new line --- l10n/l10n.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'l10n') diff --git a/l10n/l10n.pl b/l10n/l10n.pl index e3a42aefe22..2790ca92015 100644 --- a/l10n/l10n.pl +++ b/l10n/l10n.pl @@ -171,7 +171,7 @@ elsif( $task eq 'write' ){ # Write PHP file open( OUT, ">$language.php" ); - print OUT "