blib/lib/Locale/Framework/GettextXML.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 101 CC 15 SCAR 35.1
CC
15
Cov
0%
translate
56.0
load_catalog
42.0
gettextxml
20.0
CRAP 33.4
1 package Locale::Framework::GettextXML;
2  
3 use strict;
4 use XML::RAX;
5  
6 our $VERSION='0.01';
7  
8 sub new {
9 my $class=shift;
10 my $locale_path_prefix=shift or die "You need to specify a locale path prefix";;
11 my $catalog=shift or die "You need to specify a catalog to use";
12 my $debug=shift or 0;
13 my $self;
14  
15 $self->{"path"}=$locale_path_prefix;
16 $self->{"catalog"}=$catalog;
17 $self->{"lang"}="default";
18 $self->{"debug"}=$debug;
19 $self->{"mark_untranslated"}=$debug;
20  
21 bless $self,$class;
22 return $self;
23 }
24  
25 sub translate {
26 my ($self,$lang,$text)=@_;
27 print "[debug] called translate\n" if ($self->{"debug"});
28 if ($self->{"lang"} ne $lang) {
29 undef $self->{"cache"};
30 if ($lang eq "") {
31 # Return source text if this is null
32 print "[debug] language = undef\n" if ($self->{"debug"});
33 return ($self->{"mark_untranslated"} ? '*' : '' ).$text;
34 } else {
35 print "[debug] load catalog $lang\n" if ($self->{"debug"});
36 $self->load_catalog($lang);
37 }
38 $self->{"lang"}=$lang;
39 }
40 return $self->gettextxml($text);
41 }
42  
43 sub load_catalog {
44 my ($self, $lang) = @_;
45 print "[debug] called load_catalog\n" if ($self->{"debug"});
46 # Unset current catalog
47 if ($lang ne "") {
48 my $path = $self->{"path"}."/".$lang."/".$self->{"catalog"}.".xml";
49 if (-f $path) {
50 my $rax = new XML::RAX();
51 print "[debug] opening file $path\n" if ($self->{"debug"});
52 $rax->openfile($path);
53 $rax->setRecord('translation');
54 while (my $rec = $rax->readRecord()) {
55 # Cache entries
56 $self->{"cache"}->{$rec->getField('original')} = $rec->getField('translated');
57 }
58 } else {
59 # Don't load anything if we can't read the file
60 print "[debug] could not load $path\n" if ($self->{"debug"});
61 return 0;
62 }
63 }
64 }
65  
66 sub gettextxml {
67 my ($self, $phrase) = @_;
68 print "[debug] called gettextxml ( $phrase )\n" if ($self->{"debug"});
69 return $self->{"cache"}->{$phrase} if ($self->{"cache"}->{$phrase});
70 # Return source text if this is null
71 return ($self->{"mark_untranslated"} ? '*' : '' ).$phrase;
72 }
73  
74 sub set_translation {
75 return 0;
76 }
77  
78 sub clear_cache {
79 }
80  
81 my @languages=(
82 "ab",
83 "aa",
84 "af_ZA",
85 "sq_AL",
86 "am",
87 "ar",
88 "ar_DZ",
89 "ar_BH",
90 "ar_EG",
91 "ar_IQ",
92 "ar_JO",
93 "ar_KW",
94 "ar_LB",
95 "ar_LY",
96 "ar_MA",
97 "ar_OM",
98 "ar_QA",
99 "ar_SA",
100 "ar_SD",
101 "ar_SY",
102 "ar_TN",
103 "ar_AE",
104 "ar_YE",
105 "hy",
106 "as",
107 "ay",
108 "az",
109 "az",
110 "az",
111 "ba",
112 "eu_ES",
113 "be_BY",
114 "bn",
115 "dz",
116 "bh",
117 "bi",
118 "br",
119 "bg_BG",
120 "my",
121 "km",
122 "ca_ES",
123 "zh_CN",
124 "zh_CN",
125 "zh_TW",
126 "zh_HK",
127 "zh_MO",
128 "zh_SG",
129 "zh_TW",
130 "co",
131 "hr_HR",
132 "cs_CZ",
133 "da_DK",
134 "nl_NL",
135 "nl_BE",
136 "en_GB",
137 "en_GB",
138 "en_US",
139 "en_AU",
140 "en_BZ",
141 "en_BW",
142 "en_CA",
143 "en_CB",
144 "en_DK",
145 "en_IE",
146 "en_JM",
147 "en_NZ",
148 "en_PH",
149 "en_ZA",
150 "en_TT",
151 "en_ZW",
152 "eo",
153 "et_EE",
154 "fo_FO",
155 "fa_IR",
156 "fj",
157 "fi_FI",
158 "fr_FR",
159 "fr_BE",
160 "fr_CA",
161 "fr_LU",
162 "fr_MC",
163 "fr_CH",
164 "fy",
165 "gl_ES",
166 "ka",
167 "de_DE",
168 "de_AT",
169 "de_BE",
170 "de_LI",
171 "de_LU",
172 "de_CH",
173 "el_GR",
174 "kl_GL",
175 "gn",
176 "gu",
177 "ha",
178 "he_IL",
179 "hi_IN",
180 "hu_HU",
181 "is_IS",
182 "id_ID",
183 "ia",
184 "ie",
185 "iu",
186 "ik",
187 "ga_IE",
188 "it_IT",
189 "it_CH",
190 "ja_JP",
191 "jw",
192 "kn",
193 "ks",
194 "ks_IN",
195 "kk",
196 "kw_GB",
197 "rw",
198 "ky",
199 "rn",
200 "konkani",
201 "ko_KR",
202 "ku",
203 "lo",
204 "la",
205 "lv_LV",
206 "ln",
207 "lt_LT",
208 "mk_MK",
209 "mg",
210 "ms_MY",
211 "ml",
212 "ms_BN",
213 "ms_MY",
214 "mt_MT",
215 "manipuri",
216 "mi",
217 "mr_IN",
218 "mo",
219 "mn",
220 "na",
221 "ne",
222 "ne_IN",
223 "nb_NO",
224 "nn_NO",
225 "oc",
226 "or",
227 "om",
228 "ps",
229 "pl_PL",
230 "pt_PT",
231 "pt_BR",
232 "pa",
233 "qu",
234 "rm",
235 "ro_RO",
236 "ru_RU",
237 "ru_UA",
238 "sm",
239 "sg",
240 "sa",
241 "gd",
242 "sr_YU",
243 "sr_YU",
244 "sr_YU",
245 "sh",
246 "st",
247 "tn",
248 "sn",
249 "sd",
250 "si",
251 "ss",
252 "sk_SK",
253 "sl_SI",
254 "so",
255 "es_ES",
256 "es_AR",
257 "es_BO",
258 "es_CL",
259 "es_CO",
260 "es_CR",
261 "es_DO",
262 "es_EC",
263 "es_SV",
264 "es_GT",
265 "es_HN",
266 "es_MX",
267 "es_ES",
268 "es_NI",
269 "es_PA",
270 "es_PY",
271 "es_PE",
272 "es_PR",
273 "es_UY",
274 "es_US",
275 "es_VE",
276 "su",
277 "sw_KE",
278 "sv_SE",
279 "sv_FI",
280 "tl",
281 "tg",
282 "ta",
283 "tt",
284 "te",
285 "th_TH",
286 "bo",
287 "ti",
288 "to",
289 "ts",
290 "tr_TR",
291 "tk",
292 "tw",
293 "ug",
294 "uk_UA",
295 "ur",
296 "ur_IN",
297 "ur_PK",
298 "uz",
299 "uz",
300 "uz",
301 "vi_VN",
302 "vo",
303 "cy",
304 "wo",
305 "xh",
306 "yi",
307 "yo",
308 "za",
309 "zu"
310 );
311  
312 1;
313  
314 =head1 NAME
315  
316 Locale::Framework::GettextXML, a GettextXML backend for Locale::Framework
317  
318 =head1 SYNOPSIS
319  
320 use Locale::Framework;
321 use Locale::Framework::GettextXML;
322
323 my $wxloc=new Locale::Framework::GettextXML('locale', 'myprog');
324 Locale::Framework::language("en");
325  
326 print _T("This is a test");
327  
328 Locale::Framework::language("nl");
329
330 print _T("This is a test");
331  
332 =head1 ABSTRACT
333  
334 This module provides a GettextXML backend for the Locale::Framework
335 internationalization module.
336  
337 =head1 DESCRIPTION
338  
339 =head2 C<new(locale_prefix, catalog[, debug])> --E<gt> Locale::Framework::GettextXML
340  
341 Instantiates a new backend object. Optionally can "mark" untranslated strings
342 and print debugging text.
343  
344 =head2 C<translate(language,text)> --E<gt> string
345  
346 This function looks up a translation for the tuple (language, text)
347 via GettextXML.
348  
349 =head2 C<set_translation(language,text,translation)> --E<gt> boolean
350  
351 This function returns false for this backend, because GettextXML
352 does not support dynamic updating yet.
353  
354 =head2 C<clear_cache()> --E<gt> void
355  
356 This function is a noop for this backend.
357  
358 =head1 SEE ALSO
359  
360 L<Locale::Framework|Locale::Framework>
361  
362 =head1 AUTHOR
363  
364 Jeff Buchbinder <freemed@gmail.com>
365  
366 =head1 COPYRIGHT AND LICENSE
367  
368 This library is free software; you can redistribute it and/or modify
369 it under LGPL terms.
370  
371 =cut