| 1 | package XML::TMX::FromPO; | ||||||||||||||||||||||||||||||||
| 2 | 2 | $XML::TMX::FromPO::VERSION = '0.39'; | |||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Generates a TMX file from a group of PO files | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use XML::TMX::Writer; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Exporter (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 2 | our @ISA = 'Exporter'; | |||||||||||||||||||||||||||||||
| 13 | 2 | our @EXPORT_OK = qw(&new &parse_dir &create_tmx &clean_tmx); | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 17 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||
| 19 | 0 | my $self = {}; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 0 | $self->{LANG} = undef; | |||||||||||||||||||||||||||||||
| 22 | 0 | $self->{OUTPUT} = undef; | |||||||||||||||||||||||||||||||
| 23 | 0 | $self->{DEBUG} = 0; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 0 | __common_conf($self, @_); | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | unless(defined($self->{CONVER})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if(system('recode >/dev/null 2>&1')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | 0 | $self->{CONVERT} = 'iconv -f %t -t utf8 < %f'; | |||||||||||||||||||||||||||||||
| 30 | } else { | ||||||||||||||||||||||||||||||||
| 31 | 0 | $self->{CONVERT} = 'recode %t..utf8 < %f'; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 0 | $self->{TMX} = {}; | |||||||||||||||||||||||||||||||
| 36 | 0 | bless($self, $class); | |||||||||||||||||||||||||||||||
| 37 | 0 | return($self); | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub rec_get_po { | ||||||||||||||||||||||||||||||
|
Subroutine
rec_get_po: not called CC=14 SCAR=51.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 43 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 44 | 0 | my $dir = shift; | |||||||||||||||||||||||||||||||
| 45 | 0 | my $lan1 = shift; | |||||||||||||||||||||||||||||||
| 46 | 0 | __common_conf($self, @_); | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | # check if directory is readable | ||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if(-f $dir) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | 0 | my $file=$dir; | |||||||||||||||||||||||||||||||
| 51 | 0 | my $lang = lc($lan1); | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if(!defined($self->{LANG}) || __check_lang($self, $lang)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->{"LANG"} or __check_lang($self, $lang)
MC/DC0%0/2
not defined $self->{"LANG"} or __check_lang($self, $lang)
not defined $self->{"LANG"}
__check_lang($self, $lang)
Truth table0%0/3
not(A) or B
A= not defined $self->{"LANG"}B= __check_lang($self, $lang)
| |||||||||||||||||||||||||||||||||
| 54 | 0 | __processa($self, $file, $lang); | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | die("$dir is not a readable directory\n") unless(-d $dir); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | for my $file (<$dir/*>) { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if($file =~ /(.*)\.(po|messages)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 62 | 0 | my $lang = lc($lan1); | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if(!defined($self->{LANG}) || __check_lang($self, $lang)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->{"LANG"} or __check_lang($self, $lang)
MC/DC0%0/2
not defined $self->{"LANG"} or __check_lang($self, $lang)
not defined $self->{"LANG"}
__check_lang($self, $lang)
Truth table0%0/3
not(A) or B
A= not defined $self->{"LANG"}B= __check_lang($self, $lang)
| |||||||||||||||||||||||||||||||||
| 65 | 0 | __processa($self, $file, $lang); | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | elsif($file =~ /(.*)\.(\w+)\.(po|messages)$/) { | ||||||||||||||||||||||||||||||||
| 69 | 0 | my $lang = lc($lan1); | |||||||||||||||||||||||||||||||
| 70 | ## ??? my $lang = "\L$2"; | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if(!defined($self->{LANG}) || __check_lang($self, $lang)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->{"LANG"} or __check_lang($self, $lang)
MC/DC0%0/2
not defined $self->{"LANG"} or __check_lang($self, $lang)
not defined $self->{"LANG"}
__check_lang($self, $lang)
Truth table0%0/3
not(A) or B
A= not defined $self->{"LANG"}B= __check_lang($self, $lang)
| |||||||||||||||||||||||||||||||||
| 73 | 0 | __processa($self, $file, $lang); | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | elsif(-d $file) { | ||||||||||||||||||||||||||||||||
| 77 | 0 | rec_get_po($self,$file,$lan1) | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||||
| 80 | ## warn ("$file ... não tem lingua\n") if($self->{DEBUG}); | ||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | __add_en($self) if(__check_lang($self, 'en')); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | 0 | __limpa($self); | |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub parse_dir { | ||||||||||||||||||||||||||||||
|
Subroutine
parse_dir: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 93 | 0 | my $dir = shift; | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 0 | __common_conf($self, @_); | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | # check if directory is readable | ||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | die("$dir is not a readable directory\n") unless(-d $dir); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | for my $file ((<$dir/*.po>),(<$dir/*.messages>)) { | |||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if($file =~ /(\w+)\.(po|messages)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 102 | 0 | my $lang = "\L$1"; | |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if(!defined($self->{LANG}) || __check_lang($self, $lang)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->{"LANG"} or __check_lang($self, $lang)
MC/DC0%0/2
not defined $self->{"LANG"} or __check_lang($self, $lang)
not defined $self->{"LANG"}
__check_lang($self, $lang)
Truth table0%0/3
not(A) or B
A= not defined $self->{"LANG"}B= __check_lang($self, $lang)
| |||||||||||||||||||||||||||||||||
| 105 | 0 | __processa($self, $file, $lang); | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | } elsif($file =~ /(.*)\.(\w+)\.(po|messages)$/) { | ||||||||||||||||||||||||||||||||
| 108 | 0 | my $lang = "\L$2"; | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if(!defined($self->{LANG}) || __check_lang($self, $lang)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->{"LANG"} or __check_lang($self, $lang)
MC/DC0%0/2
not defined $self->{"LANG"} or __check_lang($self, $lang)
not defined $self->{"LANG"}
__check_lang($self, $lang)
Truth table0%0/3
not(A) or B
A= not defined $self->{"LANG"}B= __check_lang($self, $lang)
| |||||||||||||||||||||||||||||||||
| 111 | 0 | __processa($self, $file, $lang); | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | } else { | ||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | warn ("$file ... não tem lingua\n") if($self->{DEBUG}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | __add_en($self) if(__check_lang($self, 'en')); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 119 | 0 | __limpa($self); | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | # return value: | ||||||||||||||||||||||||||||||||
| 123 | # * 0 -> lang does not exist | ||||||||||||||||||||||||||||||||
| 124 | # * 1 -> lang exists | ||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub __check_lang { | ||||||||||||||||||||||||||||||
|
Subroutine
__check_lang: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 127 | 0 | my $lang = shift; | |||||||||||||||||||||||||||||||
| 128 | 0 | my @regex = @{$self->{LANG}}; | |||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | while(my $regex = shift(@regex)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | last if($regex gt $lang); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if($lang =~ /^$regex$/i) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | 0 | return(1); | |||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | 0 | return(0); | |||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub __add_en { | ||||||||||||||||||||||||||||||
|
Subroutine
__add_en: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 140 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 0 | for my $str (keys %{$self->{TMX}}) { | |||||||||||||||||||||||||||||||
| 143 | 0 | $self->{TMX}{$str}{'en'} = $str; | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub create_tmx { | ||||||||||||||||||||||||||||||
|
Subroutine
create_tmx: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 149 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 150 | 0 | my $tmx = new XML::TMX::Writer(); | |||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 0 | __common_conf($self, @_); | |||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | 0 | my $n_langs = @{$self->{LANG}}; | |||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if(defined($self->{OUTPUT})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 157 | 0 | $tmx->start_tmx(ID => 'XML::TMX::FromPO', OUTPUT => $self->{OUTPUT}); | |||||||||||||||||||||||||||||||
| 158 | } else { | ||||||||||||||||||||||||||||||||
| 159 | 0 | $tmx->start_tmx(ID => 'XML::TMX::FromPO'); | |||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | 0 | for my $chave (keys %{$self->{TMX}}) { | |||||||||||||||||||||||||||||||
| 163 | 0 | my $reg = __make_tu($self, $self->{TMX}{$chave}); | |||||||||||||||||||||||||||||||
| 164 | # only write to file if all languages are defined | ||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $tmx->add_tu(%{$reg}) if(keys(%{$reg}) >= $n_langs); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||
| 167 | 0 | $tmx->end_tmx(); | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub clean_tmx { | ||||||||||||||||||||||||||||||
|
Subroutine
clean_tmx: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 172 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 173 | 0 | $self->{TMX} = {}; | |||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub __make_tu { | ||||||||||||||||||||||||||||||
|
Subroutine
__make_tu: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 177 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 178 | 0 | my $block = shift; | |||||||||||||||||||||||||||||||
| 179 | 0 | my $reg = {}; | |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if(!defined($self->{LANG})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 182 | 0 | return($block); | |||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 0 | for my $lang (keys %$block) { | |||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $reg->{$lang} = $block->{$lang} if(__check_lang($self, $lang)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||
| 188 | 0 | return($reg); | |||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub __processa { | ||||||||||||||||||||||||||||||
|
Subroutine
__processa: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||||||
| 192 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 193 | 0 | my $a = shift; | |||||||||||||||||||||||||||||||
| 194 | 0 | my $l = shift; | |||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 0 | local $/ = "\nmsgid"; | |||||||||||||||||||||||||||||||
| 197 | #local $/ = "\nmsgid "; | ||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | print STDERR "$a\n" if($self->{DEBUG}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | 0 | my $codeline = `grep -i Content-Type $a | grep -i charset`; | |||||||||||||||||||||||||||||||
| 201 | 0 | my $code = "?"; | |||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if($codeline =~ /charset=([\w-]+)/) { $code = $1; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | 0 | my $convert = $self->{CONVERT}; | |||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | 0 | $convert =~ s/\%t/$code/i; | |||||||||||||||||||||||||||||||
| 208 | 0 | $convert =~ s/\%f/$a/i; | |||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if($code eq "?" || $code =~ /utf-?8/i ) { open(F,$a) or die;} | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$code eq "?" or $code =~ /utf-?8/i
MC/DC0%0/2
$code eq "?" or $code =~ /utf-?8/i
$code eq "?"
$code =~ /utf-?8/i
Truth table0%0/3
A or B
A= $code eq "?"B= $code =~ /utf-?8/i
| |||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | else { open(F,"$convert|") or die;} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 0 | my $mi = 0; | |||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | while(<F>) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 216 | 0 | chomp; | |||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | next if($mi == 0 && /^msgid\s+""/); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mi == 0 and /^msgid\s+""/
MC/DC0%0/2
$mi == 0 and /^msgid\s+""/
$mi == 0
/^msgid\s+""/
Truth table0%0/3
A and B
A= $mi == 0B= /^msgid\s+""/
| |||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if(/"Content-Type:/ && /charset=([\w-]+)/) { $code = $1; next } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/"Content-Type:/ and /charset=([\w-]+)/
MC/DC0%0/2
/"Content-Type:/ and /charset=([\w-]+)/
/"Content-Type:/
/charset=([\w-]+)/
Truth table0%0/3
A and B
A= /"Content-Type:/B= /charset=([\w-]+)/
| |||||||||||||||||||||||||||||||||
| 219 | 0 | s/(^|\n)\s*#.*//g; | |||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | # s/_//g unless $under; | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | next unless(/\n\s*msgstr/); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 224 | 0 | my ($m1,$m2) = ($`,$'); | |||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | 0 | $m1 =~ s/(^\s*"|"\s*$)//g; | |||||||||||||||||||||||||||||||
| 227 | 0 | $m1 =~ s/("\s*\n\s*")/ /g; | |||||||||||||||||||||||||||||||
| 228 | 0 | $m2 =~ s/(^\s*"|"\s*$)//g; | |||||||||||||||||||||||||||||||
| 229 | 0 | $m2 =~ s/("\s*\n\s*")/ /g; | |||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | unless($m1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 232 | 0 | warn "\n====M1 vazio... \n$m1\n=$m2\n"; | |||||||||||||||||||||||||||||||
| 233 | 0 | next; | |||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if($m2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 237 | 0 | $self->{TMX}{$m1}{$l} = $m2; | |||||||||||||||||||||||||||||||
| 238 | } # || "????? $m1"; | ||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | #$self->{TMX}{$m1}{'en'} = $m1; | ||||||||||||||||||||||||||||||||
| 241 | # print "\n====\n$m1\n=$m2\n"; | ||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | 0 | $mi++; | |||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | print STDERR "Charset: $code\n" if($self->{DEGUB}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 246 | 0 | close F; | |||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub __limpa { | ||||||||||||||||||||||||||||||
|
Subroutine
__limpa: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||
| 250 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | # possíveis limpezas | ||||||||||||||||||||||||||||||||
| 253 | # (1) eliminar traduções que sejam igual ao original | ||||||||||||||||||||||||||||||||
| 254 | # (2) eliminar strings que não contenham pelo menos 2 letras | ||||||||||||||||||||||||||||||||
| 255 | # consecutivas | ||||||||||||||||||||||||||||||||
| 256 | # (3) eliminar frases que fiquem sem traduções | ||||||||||||||||||||||||||||||||
| 257 | # | ||||||||||||||||||||||||||||||||
| 258 | # um teste realizado com os po's do evolution mostrou uma redução do | ||||||||||||||||||||||||||||||||
| 259 | # ficheiro final de 12M para 8,6M, uma análise com o diff aos dumps | ||||||||||||||||||||||||||||||||
| 260 | # permitiu ver que grande parte do ''lixo'' eram de (1) | ||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | 0 | for my $h1 (keys %{$self->{TMX}}) { | |||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if($h1 =~ /[a-z][a-z]/i) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 264 | 0 | for my $h2 (keys %{$self->{TMX}{$h1}}) { | |||||||||||||||||||||||||||||||
| 265 | # optimização (1) | ||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | delete($self->{TMX}{$h1}{$h2}) if($h2 !~ /^en/i && $h1 eq $self->{TMX}{$h1}{$h2}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $h2 =~ /^en/i and $h1 eq $self->{"TMX"}{$h1}{$h2}
MC/DC0%0/2
not $h2 =~ /^en/i and $h1 eq $self->{"TMX"}{$h1}{$h2}
not $h2 =~ /^en/i
$h1 eq $self->{"TMX"}{$h1}{$h2}
Truth table0%0/3
not(A) and B
A= not $h2 =~ /^en/iB= $h1 eq $self->{"TMX"}{$h1}{$h2}
| |||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||
| 268 | # optimização (3) | ||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | delete($self->{TMX}{$h1}) unless(keys %{$self->{TMX}{$h1}}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 270 | } else { | ||||||||||||||||||||||||||||||||
| 271 | # optimização (2) | ||||||||||||||||||||||||||||||||
| 272 | 0 | delete($self->{TMX}{$h1}); | |||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub __common_conf { | ||||||||||||||||||||||||||||||
|
Subroutine
__common_conf: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||
| 280 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 281 | 0 | my %opt = @_; | |||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if(defined($opt{LANG})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 284 | 0 | my @list; | |||||||||||||||||||||||||||||||
| 285 | 0 | for my $l (sort(split(/\s+/, $opt{LANG}))) { | |||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | push(@list, $l) if($l =~ /^[a-z0-9_]+$/i); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | $self->{LANG} = \@list if(@list); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | $self->{CONVERT} = $opt{CONVERT} if defined($opt{CONVERT}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | $self->{OUTPUT} = $opt{OUTPUT} if defined($opt{OUTPUT}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | $self->{DEBUG} = $opt{DEBUG} if defined($opt{DEBUG}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | 2 | 1; | |||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | __END__ | ||||||||||||||||||||||||||||||||