blib/lib/Locale/Framework/gettext.pm

filter: Statementstmt 93.7% 45 / 48 Branchbran 50.0% 8 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 80.0% 4 / 5 totaltotal 84.4% 65 / 77 CC 10 SCAR 12.2
CC
10
Cov
83%
new
5.3
get_locale
4.2
translate
3.0
CRAP 3.4
↑ Summary
1 package Locale::Framework::gettext;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Locale::gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION='0.04';
8  
9 1 ▶sub new {
Subroutine new: called CC=5 SCAR=16.8
Pod documented
10 1 my $class=shift;
11 1 my $local_path_prefix=shift; #or die "You need to specify a locale path prefix";;
12 1 ▶ my $catalog=shift or die "You need to specify a catalog to use";
Branch: 1 branch
BranchTrueFalseTotal
my $catalog = shift() or die "You need to specify a catalog to use" 1 0 1
13 1 my $self;
14  
15 1 $self->{"path"}=$local_path_prefix;
16 1 $self->{"catalog"}=$catalog;
17  
18 1 $self->{"lang"}=$ENV{"LANG"};
19 1 ▶ if (not defined $self->{"lang"}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->{'lang'}) { } 1 0 1
elsif ($self->{'lang'} eq '') { } 0 0 0
20 1 $self->{"lang"}="en_GB";
21 }
22 elsif ($self->{"lang"} eq "") {
23 0 $self->{"lang"}="en_GB";
24 }
25 1 my $lang=$self->{"lang"};
26  
27 1 setlocale(LC_MESSAGES,$lang);
28 1 textdomain($catalog);
29 1 ▶ if ($local_path_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local_path_prefix) 1 0 1
30 1 bindtextdomain($catalog,"$local_path_prefix");
31 }
32  
33 1 bless $self,$class;
34 1 return $self;
35 }
36  
37 4 ▶sub translate {
Subroutine translate: called CC=3 SCAR=11.1
Pod documented
38 4 my ($self,$lang,$text)=@_;
39  
40 4 ▶ if ($self->{"lang"} ne $lang) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lang"} ne $lang) 4 0 4
41 4 $lang=get_locale($lang);
42 4 setlocale(LC_MESSAGES,$lang);
43 4 $self->{"lang"}=$lang;
44  
45 4 my $local_path_prefix=$self->{"path"};
46 4 my $catalog=$self->{"catalog"};
47  
48 4 ▶ if ($local_path_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local_path_prefix) 4 0 4
49 4 bindtextdomain($catalog,"$local_path_prefix");#/$lang");
50 }
51 }
52  
53 4 return gettext($text);
54 }
55  
56 1 ▶sub set_translation {
Subroutine set_translation: called CC=1 SCAR=0.0
Pod documented
57 1 return 0;
58 }
59  
60 1 ▶sub clear_cache {
Subroutine clear_cache: called CC=1 SCAR=0.0
Pod documented
61 }
62  
63 1 my @languages=(
64 "ab",
65 "aa",
66 "af_ZA",
67 "sq_AL",
68 "am",
69 "ar",
70 "ar_DZ",
71 "ar_BH",
72 "ar_EG",
73 "ar_IQ",
74 "ar_JO",
75 "ar_KW",
76 "ar_LB",
77 "ar_LY",
78 "ar_MA",
79 "ar_OM",
80 "ar_QA",
81 "ar_SA",
82 "ar_SD",
83 "ar_SY",
84 "ar_TN",
85 "ar_AE",
86 "ar_YE",
87 "hy",
88 "as",
89 "ay",
90 "az",
91 "az",
92 "az",
93 "ba",
94 "eu_ES",
95 "be_BY",
96 "bn",
97 "dz",
98 "bh",
99 "bi",
100 "br",
101 "bg_BG",
102 "my",
103 "km",
104 "ca_ES",
105 "zh_CN",
106 "zh_CN",
107 "zh_TW",
108 "zh_HK",
109 "zh_MO",
110 "zh_SG",
111 "zh_TW",
112 "co",
113 "hr_HR",
114 "cs_CZ",
115 "da_DK",
116 "nl_NL",
117 "nl_BE",
118 "en_GB",
119 "en_GB",
120 "en_US",
121 "en_AU",
122 "en_BZ",
123 "en_BW",
124 "en_CA",
125 "en_CB",
126 "en_DK",
127 "en_IE",
128 "en_JM",
129 "en_NZ",
130 "en_PH",
131 "en_ZA",
132 "en_TT",
133 "en_ZW",
134 "eo",
135 "et_EE",
136 "fo_FO",
137 "fa_IR",
138 "fj",
139 "fi_FI",
140 "fr_FR",
141 "fr_BE",
142 "fr_CA",
143 "fr_LU",
144 "fr_MC",
145 "fr_CH",
146 "fy",
147 "gl_ES",
148 "ka",
149 "de_DE",
150 "de_AT",
151 "de_BE",
152 "de_LI",
153 "de_LU",
154 "de_CH",
155 "el_GR",
156 "kl_GL",
157 "gn",
158 "gu",
159 "ha",
160 "he_IL",
161 "hi_IN",
162 "hu_HU",
163 "is_IS",
164 "id_ID",
165 "ia",
166 "ie",
167 "iu",
168 "ik",
169 "ga_IE",
170 "it_IT",
171 "it_CH",
172 "ja_JP",
173 "jw",
174 "kn",
175 "ks",
176 "ks_IN",
177 "kk",
178 "kw_GB",
179 "rw",
180 "ky",
181 "rn",
182 "konkani",
183 "ko_KR",
184 "ku",
185 "lo",
186 "la",
187 "lv_LV",
188 "ln",
189 "lt_LT",
190 "mk_MK",
191 "mg",
192 "ms_MY",
193 "ml",
194 "ms_BN",
195 "ms_MY",
196 "mt_MT",
197 "manipuri",
198 "mi",
199 "mr_IN",
200 "mo",
201 "mn",
202 "na",
203 "ne",
204 "ne_IN",
205 "nb_NO",
206 "nn_NO",
207 "oc",
208 "or",
209 "om",
210 "ps",
211 "pl_PL",
212 "pt_PT",
213 "pt_BR",
214 "pa",
215 "qu",
216 "rm",
217 "ro_RO",
218 "ru_RU",
219 "ru_UA",
220 "sm",
221 "sg",
222 "sa",
223 "gd",
224 "sr_YU",
225 "sr_YU",
226 "sr_YU",
227 "sh",
228 "st",
229 "tn",
230 "sn",
231 "sd",
232 "si",
233 "ss",
234 "sk_SK",
235 "sl_SI",
236 "so",
237 "es_ES",
238 "es_AR",
239 "es_BO",
240 "es_CL",
241 "es_CO",
242 "es_CR",
243 "es_DO",
244 "es_EC",
245 "es_SV",
246 "es_GT",
247 "es_HN",
248 "es_MX",
249 "es_ES",
250 "es_NI",
251 "es_PA",
252 "es_PY",
253 "es_PE",
254 "es_PR",
255 "es_UY",
256 "es_US",
257 "es_VE",
258 "su",
259 "sw_KE",
260 "sv_SE",
261 "sv_FI",
262 "tl",
263 "tg",
264 "ta",
265 "tt",
266 "te",
267 "th_TH",
268 "bo",
269 "ti",
270 "to",
271 "ts",
272 "tr_TR",
273 "tk",
274 "tw",
275 "ug",
276 "uk_UA",
277 "ur",
278 "ur_IN",
279 "ur_PK",
280 "uz",
281 "uz",
282 "uz",
283 "vi_VN",
284 "vo",
285 "cy",
286 "wo",
287 "xh",
288 "yi",
289 "yo",
290 "za",
291 "zu"
292 );
293  
294 4 ▶sub get_locale {
Subroutine get_locale: called CC=4 SCAR=14.5
Pod undocumented
295 4 my $lang=shift;
296  
297 0 ▶ if ($lang eq "") { return ""; }
Branch: 1 branch
BranchTrueFalseTotal
if ($lang eq "") 0 4 4
298  
299 4 my $n=length($lang);
300 4 for my $l (@languages) {
301 214 ▶ if (lc(substr($l,0,$n)) eq lc($lang)) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc substr($l, 0, $n) eq lc $lang) 4 210 214
302 4 return $l;
303 }
304 }
305 0 return "";
306 }
307  
308 1 1;
309 __END__
↑ Summary