#!/usr/bin/perl -w
use strict;
use Path::Tiny;
use JSON;

sub exit_error {
    print STDERR "Error: ", $_[0], "\n";
    exit (exists $_[1] ? $_[1] : 1);
}

exit_error("Wrong number of arguments", 1) unless @ARGV == 2;

my ($file, $locale) = @ARGV;
my $json_text = path($file)->slurp_raw;
exit_error("Error reading $file", 2) unless defined $json_text;

my $data = decode_json($json_text);

my $changeset = $data->{$locale}{revision};
exit_error("Can't find locale $locale in $file", 3) unless $changeset;
print "$changeset\n";
