]> git.openstreetmap.org Git - rails.git/blobdiff - script/locale/merge-from-translatewiki
Rename reload_languages to reload-languages for consistency.
[rails.git] / script / locale / merge-from-translatewiki
index 103a453de108f389e233797d26e20d990b9f1312..ab89b61d9d023a38d37a3a18bfbd4fe29b1db29c 100644 (file)
@@ -23,12 +23,16 @@ merge-from-translatewiki - Get new translations from L<http://translatewiki.net>
 
 =head1 SYNOPSIS
 
+    # Run this normally, hopefully...
     merge-from-translatewiki --locales-dir=config/locales
 
     # Diff the existing files:
     config/locales$ for i in $(ls *yml | grep -v en.yml); do perl ../../script/locale/diff --dump-flat $i > $i.0 ;done
 
     # Merge and find out what changed:
+    rails_port$ perl script/locale/merge-from-translatewiki --locales-dir config/locales
+
+    # Or, more complexy:
     rails_port$ for i in $(svn st config/locales/ | egrep '^M|\\?' | awk '{print $2}' | grep 'yml$'); do rm -v $i; done && svn up config/locales && perl script/locale/merge-from-translatewiki --locales-dir config/locales && svn st config/locales
  
     # Diff:
@@ -50,7 +54,11 @@ Print this help message.
 
 =item --locales-dir
 
-The locales dir we'll merge stuff into. E.g. C<config/locales>.
+The locales dir we'll merge stuff into. F<config/locales> by default.
+
+=item --only-new
+
+Only import translations that don't exists for us yet.
 
 =back
 
@@ -65,13 +73,14 @@ Getopt::Long::Parser->new(
     config => [ qw< bundling no_ignore_case no_require_order pass_through > ],
 )->getoptions(
     'h|help' => \my $help,
-    'locales-dir=s' => \my $locales_dir,
+    'locales-dir=s' => \(my $locales_dir = 'config/locales'),
+    'only-new' => \my $only_new,
 ) or help();
 
 # On --help
 help() if $help;
 
-help() unless $locales_dir;
+help() unless $locales_dir and -d $locales_dir;
 
 ###
 ### Main
@@ -114,8 +123,8 @@ for my $translatewiki_lang (sort @translatewiki_languages_codes) {
         my $expanded = expand_hash($translatewiki_translations{$translatewiki_lang});
         my $out = +{ $rails_lang => $expanded };
         spit_out($out_file, $out);
-    } elsif (ref $my_translations{$translatewiki_lang} eq 'HASH') {
-        say STDERR "$rails_lang has existing translations. Merging";
+    } elsif (ref $my_translations{$translatewiki_lang} eq 'HASH' and not $only_new) {
+        say STDERR "$rails_lang has existing translations. Merging the old translation with the new Translatewiki one";
 
         # Get the data
         my %tw = %{ $translatewiki_translations{$translatewiki_lang} };
@@ -170,7 +179,7 @@ for my $translatewiki_lang (sort @translatewiki_languages_codes) {
                     exists $en{ $me_k . '.few' } or
                     exists $en{ $me_k . '.other' } or
                     exists $en{ $me_k . '.two' })) {
-                say STDERR "Bringing back nuked plural form '$me_k' Setting it to '$me{ $me_k }'";
+                #say STDERR "Bringing back nuked plural form '$me_k' Setting it to '$me{ $me_k }'";
                 $new{ $me_k } = $me{ $me_k };
             }
         }
@@ -190,7 +199,7 @@ for my $translatewiki_lang (sort @translatewiki_languages_codes) {
         my $expanded = expand_hash( \%new );
         my $out = +{ $rails_lang => $expanded };
         spit_out($out_file, $out);
-    } else {
+    } elsif (not $only_new) {
         die "Internal error on $translatewiki_lang";
     }
 }
@@ -201,7 +210,6 @@ sub spit_out
     my $yaml_out = Dump $data;
     
     open my $fh, ">", $file;
-    say $fh "# Imported at " . (scalar localtime) . " from Translatewiki.net";
     print $fh $yaml_out;
     close $fh;
 }
@@ -300,9 +308,12 @@ sub get_translatewiki_translations
     }
 
     my %translatewiki_languages;
-    say "All languages are: @languages";
+    my $all_count = scalar @languages;
+    say "Translatewiki has $all_count languages I'm about to get";
+    my $count = 0;
     for my $lang (@languages) {
-        say STDERR "Getting language $lang from Translatewiki";
+        $count ++;
+        say STDERR "Getting language $count/$all_count ($lang) from Translatewiki";
         my $yaml = get_language_from_translatewiki($lang);
 
         my $flat_data = load_and_flatten_yaml($yaml);