X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/8d76bf978a59f6bca6a009937589d3e2b0996e99..cea6f9c4cfc7dc1bd0dc9aa71f3a39feecb98113:/script/locale/diff diff --git a/script/locale/diff b/script/locale/diff index 0335fe983..bfc63694d 100755 --- a/script/locale/diff +++ b/script/locale/diff @@ -2,7 +2,7 @@ use feature ':5.10'; use strict; use warnings; -use YAML::Syck qw(LoadFile); +use YAML::Syck qw(Dump LoadFile); use Test::Differences; use Pod::Usage (); use Getopt::Long (); @@ -68,11 +68,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 -Evar ArnfjErE Bjarmason +Evar ArnfjErE Bjarmason =cut @@ -82,26 +87,50 @@ 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, + 'reconstruct' => \my $reconstruct, ) 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 || $reconstruct; my ($from, $to) = @ARGV; my $from_data = LoadFile($from); -my $to_data = LoadFile($to); - my $from_parsed = { iterate($from_data->{basename($from)}) }; + +if ($dump_flat) +{ + mark_utf8($from_parsed); + + print Dump $from_parsed; + + exit 0; +} + +if ($reconstruct) { + mark_utf8($from_parsed); + + my %out; + while (my ($k, $v) = each %$from_parsed) { + insert_string_deep(\%out, $k, $v); + } + + print Dump { basename($from) => \%out }; + + exit 0; +} + +my $to_data = LoadFile($to); my $to_parsed = { iterate($to_data->{basename($to)}) }; if ($keys) @@ -217,13 +246,52 @@ sub iterate return @ret; } +# $s = 'foo.bar.baz.spam.eggs.ham'; $h = \%h; $h = $h->{$_} = {} for split /\./, $s; \%h +# ==> {foo => {bar => {baz => {spam => {eggs => {ham => {}}}}}}} +sub insert_string_deep { + my ($h, $ks, $v) = @_; + my $p = \$h; $p = \$$p->{$_} for split /\./, $ks; + $$p = $v; +} + +# sub insert_string_deep +# { +# my ($hash, $key, $value) = @_; +# +# my @key = split /\./, $key; +# my $h = $hash; +# +# my $i = 0; +# for my $k (@key) { +# $i ++; +# if ($i == @key) { +# $h->{$k} = $value; +# } else { +# if (ref $h->{$k}) { +# $h = $h->{$k}; +# } else { +# $h = $h->{$k} = {}; +# } +# } +# } +# } + sub basename { my $name = shift; $name =~ s[\..*?$][]; + $name =~ s[.*/][]; $name; } +sub mark_utf8 +{ + my ($hash) = @_; + + # Mark as UTF-8 + map { if (ref $_ eq 'ARRAY') { map { utf8::decode($_) } @$_ } else { utf8::decode($_) } } values %$hash; +} + sub help { my %arg = @_; @@ -252,6 +320,9 @@ untranslated_values: 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 @@ -303,3 +374,9 @@ untranslated_values: # {{name}} ({{id}}) printable_name.with_name: true + + # {{type}} + geocoder.search_osm_namefinder.prefix: true + + # {{suffix}}, {{parentname}} + geocoder.search_osm_namefinder.suffix_suburb: true