]> git.openstreetmap.org Git - rails.git/blob - script/locale/diff
Fix interpolation argument error on user settings in pt-BR
[rails.git] / script / locale / diff
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use YAML::Syck qw(LoadFile);
5 use Data::Walk;
6 use Test::Differences;
7 use Pod::Usage ();
8 use Getopt::Long ();
9
10 =head1 NAME
11
12 locale-diff - Compare two YAML files and print how their datastructures differ
13
14 =head1 SYNOPSIS
15
16     locale-diff en.yml is.yml
17     locale-diff en.yml is.yml | grep '*'
18
19 =head1 DESCRIPTION
20
21 This utility prints the differences between two YAML files using
22 L<Test::Differences>. The purpose of it is to diff the files is
23 F<config/locales> to find out what keys need to be added to the
24 translated files when F<en.yml> changes.
25
26 =head1 OPTIONS
27
28 =over
29
30 =item -h, --help
31
32 Print this help message.
33
34 =back
35
36 =head1 AUTHOR
37
38 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@f-prot.com>
39
40 =cut
41
42 # Get the command-line options
43 Getopt::Long::Parser->new(
44     config => [ qw< bundling no_ignore_case no_require_order pass_through > ],
45 )->getoptions(
46     'h|help' => \my $help,
47 ) or help();
48
49 # On --help
50 help() if $help;
51
52 # If we're not given two .yml files
53 help() if @ARGV != 2 or (!-f $ARGV[0] or !-f $ARGV[1]);
54
55 my ($from, $to) = @ARGV;
56
57 my $from_data = LoadFile($from);
58 my $to_data   = LoadFile($to);
59
60 # Normalize the two to have the same root element
61 my ($from_key) = keys %$from_data;
62 $from_data = $from_data->{$from_key};
63
64 my ($to_key) = keys %$to_data;
65 $to_data = $to_data->{$to_key};
66
67 # Delete hash values
68 walkdepth \&delete_hash_values, $_ for $from_data, $to_data;
69
70 # Hack around Test::Differences wanting a Test::* module loaded
71 $INC{"Test.pm"} = 1;
72 sub Test::ok { print shift }
73
74 # Diff the tree
75 eq_or_diff($from_data, $to_data);
76
77 sub delete_hash_values
78 {
79     return unless defined $Data::Walk::type and $Data::Walk::type eq 'HASH';
80
81     # We totally need Perl 6's $OUTER::_ to make this prettier
82     my $hash = $_;
83
84     @$hash{grep { not ref $hash->{$_} } keys %$hash} = ();
85 }
86
87 sub help
88 {
89     my %arg = @_;
90
91     Pod::Usage::pod2usage(
92         -verbose => $arg{ verbose },
93         -exitval => $arg{ exitval } || 0,
94     );
95 }