| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use utf8; | ||
| 6 | use encoding 'utf8'; | ||
| 7 | use Pod::Usage; | ||
| 8 | use Getopt::Std; | ||
| 9 | use Locale::Maketext::AutoTranslate; | ||
| 10 | |||
| 11 | $ENV{AUTOTRANSLATE_DEBUG} = 1; | ||
| 12 | |||
| 13 | sub main { | ||
| 14 | pod2usage(1) if !@_; | ||
| 15 | getopts('f:t:i:o:h', \my %opts); | ||
| 16 | pod2usage(1) if $opts{h}; | ||
| 17 | |||
| 18 | if (!$opts{f}) { | ||
| 19 | $opts{f} ||= 'en'; | ||
| 20 | warn "Source language defaults to English\n\n"; | ||
| 21 | } | ||
| 22 | if (!$opts{i}) { | ||
| 23 | $opts{i} ||= $opts{f} . '.po'; | ||
| 24 | warn "Input file defaults to $opts{i}\n\n"; | ||
| 25 | } | ||
| 26 | if (!$opts{o}) { | ||
| 27 | $opts{o} ||= $opts{t} . '.po'; | ||
| 28 | warn "Output file defaults to $opts{o}\n\n"; | ||
| 29 | } | ||
| 30 | |||
| 31 | die "Please specify the target language" if !$opts{t}; | ||
| 32 | |||
| 33 | my $t = Locale::Maketext::AutoTranslate->new(); | ||
| 34 | |||
| 35 | $t->from($opts{f}); | ||
| 36 | $t->to($opts{t}); | ||
| 37 | |||
| 38 | $t->translate($opts{i} => $opts{o}); | ||
| 39 | |||
| 40 | warn "\nTranslation is done.\n\n"; | ||
| 41 | } | ||
| 42 | |||
| 43 | main(@ARGV); | ||
| 44 | |||
| 45 | __END__ |