| 1 |
#!/usr/bin/perl -w -s |
| 2 |
|
| 3 |
our($s); |
| 4 |
|
| 5 |
use Data::Dumper; |
| 6 |
use strict; |
| 7 |
use lib 'lib'; |
| 8 |
use XML::TMX::FromPO; |
| 9 |
|
| 10 |
my $tmx = new XML::TMX::FromPO(DEBUG => 1); |
| 11 |
my %convert = ( 'pt_en' => 'pt en', |
| 12 |
'pt_es' => 'pt es', |
| 13 |
'pt_de' => 'pt de', |
| 14 |
'pt_it' => 'pt it', |
| 15 |
'pt_ru' => 'pt ru', |
| 16 |
'pt_fr' => 'pt fr', |
| 17 |
'pt_br' => 'pt pt_BR', |
| 18 |
|
| 19 |
'br_en' => 'pt_BR en', |
| 20 |
'br_es' => 'pt_BR es', |
| 21 |
'br_de' => 'pt_BR de', |
| 22 |
'br_it' => 'pt_BR it', |
| 23 |
'br_ru' => 'pt_BR ru', |
| 24 |
'br_fr' => 'pt_BR fr', |
| 25 |
|
| 26 |
'en_fr' => 'en fr' |
| 27 |
); |
| 28 |
|
| 29 |
if($s){ |
| 30 |
my $lang = $s; |
| 31 |
if ($s eq "1") { die("Usage $0 -s=pt DIR\n")} |
| 32 |
|
| 33 |
while(my $dir = shift()) { |
| 34 |
$tmx->rec_get_po($dir, $lang, LANG=>"$lang en"); |
| 35 |
open(XML, "| tee _1.aux |xmllint --recover --format - | bzip2 > $lang-en.tmx.bz2"); |
| 36 |
# print STDOUT Dumper($tmx); |
| 37 |
*STDOUT = *XML; |
| 38 |
$tmx->create_tmx(LANG => "$lang en"); |
| 39 |
close(XML); |
| 40 |
$tmx->clean_tmx() |
| 41 |
} |
| 42 |
} |
| 43 |
else{ |
| 44 |
|
| 45 |
my $lang = ''; |
| 46 |
for my $c (keys %convert) { |
| 47 |
$lang = $lang . " $convert{$c}"; |
| 48 |
} |
| 49 |
|
| 50 |
while(my $dir = shift()) { |
| 51 |
if(-d "$dir/po" and <$dir/po/*.po>){ $tmx->parse_dir("$dir/po", LANG => $lang) ; } |
| 52 |
if(-d "$dir" and <$dir/*.po>) { $tmx->parse_dir("$dir", LANG => $lang) ; } |
| 53 |
$dir =~ m/([a-z0-9_\.-]+)\/*$/i; |
| 54 |
for my $conv (keys %convert) { |
| 55 |
open(XML, "|xmllint --format - | bzip2 > $1_$conv.tmx.bz2"); |
| 56 |
*STDOUT = *XML; |
| 57 |
$tmx->create_tmx(LANG => "$convert{$conv}"); |
| 58 |
close(XML); |
| 59 |
} |
| 60 |
$tmx->clean_tmx() |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
=encoding UTF-8 |
| 65 |
|
| 66 |
=head1 NAME |
| 67 |
|
| 68 |
po2tmx - creates TMX files from PO files |
| 69 |
|
| 70 |
=head1 SYNOPSIS |
| 71 |
|
| 72 |
po2tmx POdir # |
| 73 |
po2tmx -s=fr #single PO files en-fr (does not join multiple PO-files) |
| 74 |
|
| 75 |
=head1 DESCRIPTION |
| 76 |
|
| 77 |
read several POs, and joinds their translation units to build several |
| 78 |
TMX pairs. |
| 79 |
|
| 80 |
=head1 SEE ALSO |
| 81 |
|
| 82 |
XML::TMX |
| 83 |
|
| 84 |
=cut |