4 use YAML::Syck qw(LoadFile);
11 locale-diff - Compare two YAML files and print how their datastructures differ
16 # --keys is the default
17 diff --keys en.yml is.yml
18 # --untranslated-values compares prints keys whose values don't differ
19 diff --untranslated-values en.yml is.yml
23 This utility prints the differences between two YAML files using
24 L<Test::Differences>. The purpose of it is to diff the files is
25 F<config/locales> to find out what keys need to be added to the
26 translated files when F<en.yml> changes.
34 Print this help message.
38 Show the hash keys that differ between the two files, useful merging
39 new entries from F<en.yml> to a local file.
41 =item --untranslated-values
43 Show keys whose values are either exactly the same between the two
44 files, or don't exist in the target file (the latter file specified).
46 This helps to find untranslated values.
52 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@f-prot.com>
56 # Get the command-line options
57 Getopt::Long::Parser->new(
58 config => [ qw< bundling no_ignore_case no_require_order pass_through > ],
60 'h|help' => \my $help,
62 'untranslated-values' => \my $untranslated_values,
68 # If we're not given two .yml files
69 help() if @ARGV != 2 or (!-f $ARGV[0] or !-f $ARGV[1]);
71 my ($from, $to) = @ARGV;
73 my $from_data = LoadFile($from);
74 my $to_data = LoadFile($to);
76 my $from_parsed = { iterate($from_data->{basename($from)}) };
77 my $to_parsed = { iterate($to_data->{basename($to)}) };
79 # Since this used to be the default, support that...
80 if ((not $untranslated_values and not $keys) or $keys)
82 print_key_differences();
84 elsif ($untranslated_values)
86 my @untranslated = untranslated_keys($from_parsed, $to_parsed);
88 print $_, "\n" for @untranslated;
93 sub print_key_differences
95 # Hack around Test::Differences wanting a Test::* module loaded
97 sub Test::ok { print shift }
100 eq_or_diff([ sort keys %$from_parsed ], [ sort keys %$to_parsed ]);
103 sub untranslated_keys
105 my ($from_parsed, $to_parsed) = @_;
106 sort grep { not exists $to_parsed->{$_} or $from_parsed->{$_} eq $to_parsed->{$_} } keys %$from_parsed;
111 my ($hash, @path) = @_;
114 while (my ($k, $v) = each %$hash)
116 if (ref $v eq 'HASH')
118 push @ret => iterate($v, @path, $k);
122 push @ret => join(".",@path, $k), $v;
132 $name =~ s[\..*?$][];
140 Pod::Usage::pod2usage(
141 -verbose => $arg{ verbose },
142 -exitval => $arg{ exitval } || 0,