X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/d3dd0229cb09c0de412f8d1e96d2ab07727cc530..4aa3a003abc129d5a060f902654d5d88a6f4906b:/script/locale/diff diff --git a/script/locale/diff b/script/locale/diff index d38f1c505..2afffb828 100755 --- a/script/locale/diff +++ b/script/locale/diff @@ -12,8 +12,11 @@ locale-diff - Compare two YAML files and print how their datastructures differ =head1 SYNOPSIS - locale-diff en.yml is.yml - locale-diff en.yml is.yml | grep '*' + diff en.yml is.yml + # --keys is the default + diff --keys en.yml is.yml + # --untranslated-values compares prints keys whose values don't differ + diff --untranslated-values en.yml is.yml =head1 DESCRIPTION @@ -30,6 +33,18 @@ translated files when F changes. Print this help message. +=item --keys + +Show the hash keys that differ between the two files, useful merging +new entries from F 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). + +This helps to find untranslated values. + =back =head1 AUTHOR @@ -43,6 +58,8 @@ Getopt::Long::Parser->new( config => [ qw< bundling no_ignore_case no_require_order pass_through > ], )->getoptions( 'h|help' => \my $help, + 'keys' => \my $keys, + 'untranslated-values' => \my $untranslated_values, ) or help(); # On --help @@ -59,18 +76,36 @@ my $to_data = LoadFile($to); my $from_parsed = { iterate($from_data->{basename($from)}) }; my $to_parsed = { iterate($to_data->{basename($to)}) }; -# Delete hash values -#walkdepth \&delete_hash_values, $_ for $from_data, $to_data; - -# Hack around Test::Differences wanting a Test::* module loaded -$INC{"Test.pm"} = 1; -sub Test::ok { print shift } +# Since this used to be the default, support that... +if ((not $untranslated_values and not $keys) or $keys) +{ + print_key_differences(); +} +elsif ($untranslated_values) +{ + my @untranslated = untranslated_keys($from_parsed, $to_parsed); -# Diff the tree -eq_or_diff([ sort keys %$from_parsed ], [ sort keys %$to_parsed ]); + print $_, "\n" for @untranslated; +} exit 0; +sub print_key_differences +{ + # Hack around Test::Differences wanting a Test::* module loaded + $INC{"Test.pm"} = 1; + sub Test::ok { print shift } + + # Diff the tree + eq_or_diff([ sort keys %$from_parsed ], [ sort keys %$to_parsed ]); +} + +sub untranslated_keys +{ + my ($from_parsed, $to_parsed) = @_; + sort grep { not exists $to_parsed->{$_} or $from_parsed->{$_} eq $to_parsed->{$_} } keys %$from_parsed; +} + sub iterate { my ($hash, @path) = @_;