4 use YAML::Syck qw(LoadFile);
11 locale-diff - Compare two YAML files and print how their datastructures differ
15 locale-diff en.yml is.yml
16 locale-diff en.yml is.yml | grep '*'
20 This utility prints the differences between two YAML files using
21 L<Test::Differences>. The purpose of it is to diff the files is
22 F<config/locales> to find out what keys need to be added to the
23 translated files when F<en.yml> changes.
31 Print this help message.
35 Show the hash keys that differ between the two files, useful merging
36 new entries from F<en.yml> to a local file.
38 =item --untranslated-values
40 Show keys whose values are either exactly the same between the two
41 files, or don't exist in the target file (the latter file specified).
43 This helps to find untranslated values.
49 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@f-prot.com>
53 # Get the command-line options
54 Getopt::Long::Parser->new(
55 config => [ qw< bundling no_ignore_case no_require_order pass_through > ],
57 'h|help' => \my $help,
58 'diff-keys' => \my $diff_keys,
59 'undiff-values' => \my $undiff_values,
65 # If we're not given two .yml files
66 help() if @ARGV != 2 or (!-f $ARGV[0] or !-f $ARGV[1]);
68 my ($from, $to) = @ARGV;
70 my $from_data = LoadFile($from);
71 my $to_data = LoadFile($to);
73 my $from_parsed = { iterate($from_data->{basename($from)}) };
74 my $to_parsed = { iterate($to_data->{basename($to)}) };
76 # Since this used to be the default, support that...
77 if ((not $undiff_values and not $diff_keys) or $diff_keys)
79 print_key_differences();
81 elsif ($undiff_values)
83 my @untranslated = untranslated_keys($from_parsed, $to_parsed);
85 print $_, "\n" for @untranslated;
90 sub print_key_differences
92 # Hack around Test::Differences wanting a Test::* module loaded
94 sub Test::ok { print shift }
97 eq_or_diff([ sort keys %$from_parsed ], [ sort keys %$to_parsed ]);
100 sub untranslated_keys
102 my ($from_parsed, $to_parsed) = @_;
103 sort grep { not exists $to_parsed->{$_} or $from_parsed->{$_} eq $to_parsed->{$_} } keys %$from_parsed;
108 my ($hash, @path) = @_;
111 while (my ($k, $v) = each %$hash)
113 if (ref $v eq 'HASH')
115 push @ret => iterate($v, @path, $k);
119 push @ret => join(".",@path, $k), $v;
129 $name =~ s[\..*?$][];
137 Pod::Usage::pod2usage(
138 -verbose => $arg{ verbose },
139 -exitval => $arg{ exitval } || 0,