| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # PODNAME: po2json | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Convert a PO file to the JSON data for Locale::Simple in the browser | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | our $VERSION = '0.200'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Locale::Simple::PO2JSON qw( po2data data2json ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | my $usage = "Usage: po2json [-p] FILE.po > FILE.json\n" | |||||||||||||||||||||||||||||||||||||||||
| 13 | . " -p indent the output and wrap it in the file name as domain\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | my $pretty = 0; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | if ( @ARGV and $ARGV[0] eq '-p' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@ARGV and $ARGV[0] eq "-p"
MC/DC100%2/2
@ARGV and $ARGV[0] eq "-p"
@ARGV
$ARGV[0] eq "-p"
Truth table100%3/3
A and B
A= @ARGVB= $ARGV[0] eq "-p"
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | $pretty = 1; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # Deprecated: one line on STDERR, STDOUT stays the clean JSON. Only -p has an | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # exact replacement; the plain form has none, the notice says what differs. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 12 | ▶ | my $instead = $pretty | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | ? 'locale-simple po2json --pretty FILE.po' | ||||||||||||||||||||||||||||||||||||||||||
| 24 | : 'locale-simple po2json FILE.po (no exact equivalent: it wraps the data as { "FILE": ... })'; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 12 | print STDERR 'po2json is deprecated, use: ' . $instead . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | ▶ | if ( !@ARGV or $ARGV[0] =~ /^(?:-h|--help)$/ or @ARGV > 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not @ARGV or $ARGV[0] =~ /^(?:-h|--help)$/ or @ARGV > 1
not @ARGV or $ARGV[0] =~ /^(?:-h|--help)$/
MC/DC100%3/3
not @ARGV or $ARGV[0] =~ /^(?:-h|--help)$/ or @ARGV > 1
not @ARGV
$ARGV[0] =~ /^(?:-h|--help)$/
@ARGV > 1
Truth table100%4/4
not(A) or B or C
A= not @ARGVB= $ARGV[0] =~ /^(?:-h|--help)$/C= @ARGV > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | print STDERR $usage; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | my ($file) = @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | my $json = eval { | |||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | $pretty | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | ? data2json( po2data( $file, domain => File::Basename::basename( $file, '.po', '.pot' ) ), pretty => 1 ) | ||||||||||||||||||||||||||||||||||||||||||
| 35 | : data2json( po2data($file) ); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 6 | ▶ | if ( !defined $json ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | print STDERR $@; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | print $json, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | __END__ | ||||||||||||||||||||||||||||||||||||||||||