#!/usr/bin/env perl # PODNAME: po2json # ABSTRACT: Convert a PO file to the JSON data for Locale::Simple in the browser our $VERSION = '0.201'; use strict; use warnings; use File::Basename (); use Locale::Simple::PO2JSON qw( po2data data2json ); my $usage = "Usage: po2json [-p] FILE.po > FILE.json\n" . " -p indent the output and wrap it in the file name as domain\n"; my $pretty = 0; if ( @ARGV and $ARGV[0] eq '-p' ) { shift @ARGV; $pretty = 1; } # Deprecated: one line on STDERR, STDOUT stays the clean JSON. Only -p has an # exact replacement; the plain form has none, the notice says what differs. my $instead = $pretty ? 'locale-simple po2json --pretty FILE.po' : 'locale-simple po2json FILE.po (no exact equivalent: it wraps the data as { "FILE": ... })'; print STDERR 'po2json is deprecated, use: ' . $instead . "\n"; if ( !@ARGV or $ARGV[0] =~ /^(?:-h|--help)$/ or @ARGV > 1 ) { print STDERR $usage; exit 1; } my ($file) = @ARGV; my $json = eval { $pretty ? data2json( po2data( $file, domain => File::Basename::basename( $file, '.po', '.pot' ) ), pretty => 1 ) : data2json( po2data($file) ); }; if ( !defined $json ) { print STDERR $@; exit 1; } print $json, "\n"; __END__ =encoding utf8 =head1 SYNOPSIS B use L instead. C writes exactly what C writes. C has no exact equivalent: C writes the same data wrapped as C<{ "FILE": ... }> (C<--domain NAME> sets the key), the shape the JavaScript C takes. Every call prints a deprecation notice on STDERR; the output and the exit codes are unchanged. po2json messages.po > messages.json po2json -p messages.po > messages.json =head1 DESCRIPTION Reads a PO file and writes the JSON data for the JavaScript side of L to STDOUT. Entries without a translation, fuzzy entries and obsolete entries are left out, as msgfmt leaves them out of a C<.mo> file. With C<-p> the output is indented and wrapped in the file name (without C<.po> or C<.pot>) as domain. C<-h> prints the usage and exits with C<1>, as does an unreadable or malformed file, with the reason on STDERR. See L for the same conversion as a subcommand. =cut