From ca911e928ece17f3e697ef0cd970cc0f9b83a1ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 22 Jun 2009 18:32:01 +0000 Subject: [PATCH 1/1] Support blacklists/whitelists for --untranslated-values output --- script/locale/diff | 78 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/script/locale/diff b/script/locale/diff index 2afffb828..7ddfb3eb3 100755 --- a/script/locale/diff +++ b/script/locale/diff @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use YAML::Syck qw(LoadFile); +use YAML::Syck qw(Load LoadFile); use Test::Differences; use Pod::Usage (); use Getopt::Long (); @@ -12,11 +12,17 @@ locale-diff - Compare two YAML files and print how their datastructures differ =head1 SYNOPSIS - diff en.yml is.yml # --keys is the default + diff en.yml is.yml diff --keys en.yml is.yml + # --untranslated-values compares prints keys whose values don't differ - diff --untranslated-values en.yml is.yml + diff --untranslated-values-all en.yml is.yml + + # --untranslated-values-all compares prints keys whose values + # don't differ. Ignoring the blacklist which prunes things + # unlikley to be translated + diff --untranslated-values-all en.yml is.yml =head1 DESCRIPTION @@ -41,10 +47,16 @@ 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). +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. This helps to find untranslated values. +=item --untranslated-values-all + +Like C<--untranslated-values> but ignores blacklists. + =back =head1 AUTHOR @@ -60,8 +72,12 @@ Getopt::Long::Parser->new( 'h|help' => \my $help, 'keys' => \my $keys, 'untranslated-values' => \my $untranslated_values, + 'untranslated-values-all' => \my $untranslated_values_all, ) or help(); +# --keys is the default +$keys = 1 if not $untranslated_values_all and not $untranslated_values; + # On --help help() if $help; @@ -77,14 +93,19 @@ my $from_parsed = { iterate($from_data->{basename($from)}) }; my $to_parsed = { iterate($to_data->{basename($to)}) }; # Since this used to be the default, support that... -if ((not $untranslated_values and not $keys) or $keys) +if ($keys) { print_key_differences(); } -elsif ($untranslated_values) +elsif ($untranslated_values or $untranslated_values_all) { my @untranslated = untranslated_keys($from_parsed, $to_parsed); + # Prune according to blacklist + if ($untranslated_values) { + @untranslated = prune_untranslated_with_blacklist(basename($to), @untranslated); + } + print $_, "\n" for @untranslated; } @@ -103,7 +124,33 @@ 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; + grep { not exists $to_parsed->{$_} or $from_parsed->{$_} eq $to_parsed->{$_} } keys %$from_parsed; +} + +sub prune_untranslated_with_blacklist +{ + my ($language, @keys) = @_; + my %keys; + @keys{@keys} = (); + + my $end_yaml = Load(join '', ); + my $untranslated_values = $end_yaml->{untranslated_values}; + my $default = $untranslated_values->{default}; + my $this_language = $untranslated_values->{$language} || {}; + + my %bw_list = (%$default, %$this_language); + + use feature ':5.10'; + use Data::Dump 'dump'; + say STDERR dump \%bw_list; + + while (my ($key, $blacklisted) = each %bw_list) + { + # FIXME: Does syck actually support true/false booleans in yaml? + delete $keys{$key} if $blacklisted eq 'true' + } + + sort keys %keys; } sub iterate @@ -142,3 +189,20 @@ sub help -exitval => $arg{ exitval } || 0, ); } + +__DATA__ +untranslated_values: + + # Default/Per language blacklist/whitelist for the + # --untranslated-values switch. "true" as a value indicates that the + # key is to be blacklisted, and "false" that it's to be + # whitelisted. "false" is only required to whitelist a key + # blacklisted by default on a per-language basis. + + default: + html.dir: true + layouts.intro_3_bytemark: true + layouts.intro_3_ucl: true + de: + layouts.export: true + -- 2.39.5