]> git.openstreetmap.org Git - rails.git/blobdiff - script/locale/diff
Deal with values which are arrays, before and after:
[rails.git] / script / locale / diff
index ddfe5913ce2390cabc399b81e3cea8bee4969da5..aa44ea53de27a404c07ac21e564f142a48f69c6c 100755 (executable)
@@ -2,10 +2,11 @@
 use feature ':5.10';
 use strict;
 use warnings;
-use YAML::Syck qw(Load LoadFile);
+use YAML::Syck qw(Dump LoadFile);
 use Test::Differences;
 use Pod::Usage ();
 use Getopt::Long ();
+use File::Basename qw(fileparse);
 
 =head1 NAME
 
@@ -50,10 +51,12 @@ new entries from F<en.yml> to a local file.
 
 =item --untranslated-values
 
-Show keys whose values are either exactly the same between the two
-files, or don't exist in the target file (the latter file
-specified). The values are pruned according to global and language
-specific blacklists found in the C<__DATA__> section of this script.
+Show keys that B<exist in both the compared files> and whose values
+are exactly the same. Use C<--keys> to a list of values that hasn't
+been merged.
+
+The values are pruned according to global and language specific
+blacklists found in the C<__DATA__> section of this script.
 
 This helps to find untranslated values.
 
@@ -66,11 +69,16 @@ Like C<--untranslated-values> but ignores blacklists.
 Check that interpolated Ruby i18n variables (C<{{foo}}> and
 C<[[foo]]>) are equivalent in the two provided files.
 
+=item --dump-flat
+
+Dump a flat version of the translation hash in YAML format,
+i.e. "foo.bar" instead of "{foo}->{bar}".
+
 =back
 
 =head1 AUTHOR
 
-E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@f-prot.com>
+E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
 
 =cut
 
@@ -80,27 +88,38 @@ Getopt::Long::Parser->new(
 )->getoptions(
     'h|help' => \my $help,
     'keys' => \my $keys,
+    'dump-flat' => \my $dump_flat,
     'untranslated-values' => \my $untranslated_values,
     'untranslated-values-all' => \my $untranslated_values_all,
     'validate-variables' => \my $validate_variables,
 ) or help();
 
 # --keys is the default
-$keys = 1 if not $untranslated_values_all and not $untranslated_values and not $validate_variables;
+$keys = 1 if not $untranslated_values_all and not $untranslated_values and not $validate_variables and not $dump_flat;
 
 # On --help
 help() if $help;
 
 # If we're not given two .yml files
-help() if @ARGV != 2 or (!-f $ARGV[0] or !-f $ARGV[1]);
+help() if (@ARGV != 2 or (!-f $ARGV[0] or !-f $ARGV[1])) and not $dump_flat;
 
 my ($from, $to) = @ARGV;
 
 my $from_data = LoadFile($from);
-my $to_data   = LoadFile($to);
+my $from_parsed = { iterate($from_data->{fileparse($from, qr/\.[^.]*/)}) };
+
+if ($dump_flat)
+{
+    # Mark as UTF-8
+    map { if (ref $_ eq 'ARRAY') { map { utf8::decode($_) } @$_ } else {  utf8::decode($_) } } values %$from_parsed;
 
-my $from_parsed = { iterate($from_data->{basename($from)}) };
-my $to_parsed = { iterate($to_data->{basename($to)}) };
+    print Dump $from_parsed;
+
+    exit 0;
+}
+
+my $to_data   = LoadFile($to);
+my $to_parsed = { iterate($to_data->{fileparse($to, qr/\.[^.]*/)}) };
 
 if ($keys)
 {
@@ -112,7 +131,7 @@ elsif ($untranslated_values or $untranslated_values_all)
 
     # Prune according to blacklist
     if ($untranslated_values) {
-        @untranslated = prune_untranslated_with_blacklist(basename($to), @untranslated);
+        @untranslated = prune_untranslated_with_blacklist(scalar(fileparse($to, qr/\.[^.]*/)), @untranslated);
     }
 
     say for @untranslated;
@@ -138,7 +157,7 @@ sub print_key_differences
 sub untranslated_keys
 {
     my ($from_parsed, $to_parsed) = @_;
-    sort grep { not exists $to_parsed->{$_} or $from_parsed->{$_} eq $to_parsed->{$_} } keys %$from_parsed;
+    sort grep { exists $to_parsed->{$_} and $from_parsed->{$_} eq $to_parsed->{$_} } keys %$from_parsed;
 }
 
 sub prune_untranslated_with_blacklist
@@ -147,7 +166,7 @@ sub prune_untranslated_with_blacklist
     my %keys;
     @keys{@keys} = ();
 
-    my $end_yaml = Load(join '', <DATA>);
+    my $end_yaml = LoadFile(*DATA);
     my $untranslated_values = $end_yaml->{untranslated_values};
     my $default = $untranslated_values->{default};
     my $this_language = $untranslated_values->{$language} || {};
@@ -215,13 +234,6 @@ sub iterate
     return @ret;
 }
 
-sub basename
-{
-    my $name = shift;
-    $name =~ s[\..*?$][];
-    $name;
-}
-
 sub help
 {
     my %arg = @_;
@@ -248,6 +260,11 @@ untranslated_values:
     layouts.project_name.h1: true
     layouts.project_name.title: true
     site.index.license.project_url: true
+    browse.relation_member.entry: true
+
+    # #{{id}}
+    changeset.changeset.id: true
+
   de:
     activerecord.attributes.message.sender: true
     activerecord.attributes.trace.name: true
@@ -284,3 +301,24 @@ untranslated_values:
     trace.view.tags: true
     user.account.public editing.enabled link: true
 
+  is:
+    # ({{link}})
+    site.edit.anon_edits: true
+
+    # Creative Commons Attribution-Share Alike 2.0
+    site.index.license.license_name: true
+
+    # http://creativecommons.org/licenses/by-sa/2.0/
+    site.index.license.license_url: true
+
+    # {{id}}
+    printable_name.with_id: true
+    
+    # {{name}} ({{id}})
+    printable_name.with_name: true
+
+    # {{type}} 
+    geocoder.search_osm_namefinder.prefix: true
+
+    # {{suffix}}, {{parentname}}
+    geocoder.search_osm_namefinder.suffix_suburb: true