@@ -32,7 +32,6 @@ LC_MESSAGES 5
3232LC_ALL 6
3333*/
3434
35-
3635// LC_MESSAGES is not available if php-gettext is not loaded
3736// while the other constants are already available from session extension.
3837if (!defined ('LC_MESSAGES ' )) {
@@ -168,21 +167,20 @@ function _check_locale_and_function($function=false) {
168167function _get_codeset ($ domain =null ) {
169168 global $ text_domains , $ default_domain , $ LC_CATEGORIES ;
170169 if (!isset ($ domain )) $ domain = $ default_domain ;
171- return (isset ($ text_domains [$ domain ]->codeset ))? $ text_domains [$ domain ]->codeset : ini_get ('mbstring.internal_encoding ' );
170+ return (isset ($ text_domains [$ domain ]->codeset ))? $ text_domains [$ domain ]->codeset : ini_get ('default_charset ' );
172171}
173172
174173/**
175174 * Convert the given string to the encoding set by bind_textdomain_codeset.
176175 */
177176function _encode ($ text ) {
177+ $ target_encoding = _get_codeset ();
178+ if (function_exists ("mb_detect_encoding " )) {
178179 $ source_encoding = mb_detect_encoding ($ text );
179- $ target_encoding = _get_codeset ();
180- if ($ source_encoding != $ target_encoding ) {
181- return mb_convert_encoding ($ text , $ target_encoding , $ source_encoding );
182- }
183- else {
184- return $ text ;
185- }
180+ if ($ source_encoding != $ target_encoding )
181+ $ text = mb_convert_encoding ($ text , $ target_encoding , $ source_encoding );
182+ }
183+ return $ text ;
186184}
187185
188186
@@ -229,7 +227,9 @@ function _setlocale($category, $locale) {
229227 }
230228 // Allow locale to be changed on the go for one translation domain.
231229 global $ text_domains , $ default_domain ;
232- unset($ text_domains [$ default_domain ]->l10n );
230+ if (array_key_exists ($ default_domain , $ text_domains )) {
231+ unset($ text_domains [$ default_domain ]->l10n );
232+ }
233233 return $ CURRENTLOCALE ;
234234 }
235235}
@@ -288,9 +288,9 @@ function __($msgid) {
288288/**
289289 * Plural version of gettext.
290290 */
291- function _ngettext ($ single , $ plural , $ number ) {
291+ function _ngettext ($ singular , $ plural , $ number ) {
292292 $ l10n = _get_reader ();
293- return _encode ($ l10n ->ngettext ($ single , $ plural , $ number ));
293+ return _encode ($ l10n ->ngettext ($ singular , $ plural , $ number ));
294294}
295295
296296/**
@@ -304,9 +304,9 @@ function _dgettext($domain, $msgid) {
304304/**
305305 * Plural version of dgettext.
306306 */
307- function _dngettext ($ domain , $ single , $ plural , $ number ) {
307+ function _dngettext ($ domain , $ singular , $ plural , $ number ) {
308308 $ l10n = _get_reader ($ domain );
309- return _encode ($ l10n ->ngettext ($ single , $ plural , $ number ));
309+ return _encode ($ l10n ->ngettext ($ singular , $ plural , $ number ));
310310}
311311
312312/**
@@ -319,9 +319,9 @@ function _dcgettext($domain, $msgid, $category) {
319319/**
320320 * Plural version of dcgettext.
321321 */
322- function _dcngettext ($ domain , $ single , $ plural , $ number , $ category ) {
322+ function _dcngettext ($ domain , $ singular , $ plural , $ number , $ category ) {
323323 $ l10n = _get_reader ($ domain , $ category );
324- return _encode ($ l10n ->ngettext ($ single , $ plural , $ number ));
324+ return _encode ($ l10n ->ngettext ($ singular , $ plural , $ number ));
325325}
326326
327327/**
@@ -405,29 +405,29 @@ function T_($msgid) {
405405 if (_check_locale_and_function ()) return _ ($ msgid );
406406 return __ ($ msgid );
407407}
408- function T_ngettext ($ single , $ plural , $ number ) {
408+ function T_ngettext ($ singular , $ plural , $ number ) {
409409 if (_check_locale_and_function ())
410- return ngettext ($ single , $ plural , $ number );
411- else return _ngettext ($ single , $ plural , $ number );
410+ return ngettext ($ singular , $ plural , $ number );
411+ else return _ngettext ($ singular , $ plural , $ number );
412412}
413413function T_dgettext ($ domain , $ msgid ) {
414414 if (_check_locale_and_function ()) return dgettext ($ domain , $ msgid );
415415 else return _dgettext ($ domain , $ msgid );
416416}
417- function T_dngettext ($ domain , $ single , $ plural , $ number ) {
417+ function T_dngettext ($ domain , $ singular , $ plural , $ number ) {
418418 if (_check_locale_and_function ())
419- return dngettext ($ domain , $ single , $ plural , $ number );
420- else return _dngettext ($ domain , $ single , $ plural , $ number );
419+ return dngettext ($ domain , $ singular , $ plural , $ number );
420+ else return _dngettext ($ domain , $ singular , $ plural , $ number );
421421}
422422function T_dcgettext ($ domain , $ msgid , $ category ) {
423423 if (_check_locale_and_function ())
424424 return dcgettext ($ domain , $ msgid , $ category );
425425 else return _dcgettext ($ domain , $ msgid , $ category );
426426}
427- function T_dcngettext ($ domain , $ single , $ plural , $ number , $ category ) {
427+ function T_dcngettext ($ domain , $ singular , $ plural , $ number , $ category ) {
428428 if (_check_locale_and_function ())
429- return dcngettext ($ domain , $ single , $ plural , $ number , $ category );
430- else return _dcngettext ($ domain , $ single , $ plural , $ number , $ category );
429+ return dcngettext ($ domain , $ singular , $ plural , $ number , $ category );
430+ else return _dcngettext ($ domain , $ singular , $ plural , $ number , $ category );
431431}
432432
433433function T_pgettext ($ context , $ msgid ) {
@@ -451,26 +451,27 @@ function T_dcpgettext($domain, $context, $msgid, $category) {
451451 return _dcpgettext ($ domain , $ context , $ msgid , $ category );
452452}
453453
454- function T_npgettext ($ context , $ singular , $ plural ) {
454+ function T_npgettext ($ context , $ singular , $ plural, $ number ) {
455455 if (_check_locale_and_function ('npgettext ' ))
456- return npgettext ($ context , $ single , $ plural , $ number );
456+ return npgettext ($ context , $ singular , $ plural , $ number );
457457 else
458- return _npgettext ($ context , $ single , $ plural , $ number );
458+ return _npgettext ($ context , $ singular , $ plural , $ number );
459459}
460460
461- function T_dnpgettext ($ domain , $ context , $ singular , $ plural ) {
461+ function T_dnpgettext ($ domain , $ context , $ singular , $ plural, $ number ) {
462462 if (_check_locale_and_function ('dnpgettext ' ))
463- return dnpgettext ($ domain , $ context , $ single , $ plural , $ number );
463+ return dnpgettext ($ domain , $ context , $ singular , $ plural , $ number );
464464 else
465- return _dnpgettext ($ domain , $ context , $ single , $ plural , $ number );
465+ return _dnpgettext ($ domain , $ context , $ singular , $ plural , $ number );
466466}
467467
468- function T_dcnpgettext ($ domain , $ context , $ singular , $ plural , $ category ) {
468+ function T_dcnpgettext ($ domain , $ context , $ singular , $ plural ,
469+ $ number , $ category ) {
469470 if (_check_locale_and_function ('dcnpgettext ' ))
470- return dcnpgettext ($ domain , $ context , $ single ,
471+ return dcnpgettext ($ domain , $ context , $ singular ,
471472 $ plural , $ number , $ category );
472473 else
473- return _dcnpgettext ($ domain , $ context , $ single ,
474+ return _dcnpgettext ($ domain , $ context , $ singular ,
474475 $ plural , $ number , $ category );
475476}
476477
@@ -494,39 +495,39 @@ if (!function_exists('gettext')) {
494495 function _ ($ msgid ) {
495496 return __ ($ msgid );
496497 }
497- function ngettext ($ single , $ plural , $ number ) {
498- return _ngettext ($ single , $ plural , $ number );
498+ function ngettext ($ singular , $ plural , $ number ) {
499+ return _ngettext ($ singular , $ plural , $ number );
499500 }
500501 function dgettext ($ domain , $ msgid ) {
501502 return _dgettext ($ domain , $ msgid );
502503 }
503- function dngettext ($ domain , $ single , $ plural , $ number ) {
504- return _dngettext ($ domain , $ single , $ plural , $ number );
504+ function dngettext ($ domain , $ singular , $ plural , $ number ) {
505+ return _dngettext ($ domain , $ singular , $ plural , $ number );
505506 }
506507 function dcgettext ($ domain , $ msgid , $ category ) {
507508 return _dcgettext ($ domain , $ msgid , $ category );
508509 }
509- function dcngettext ($ domain , $ single , $ plural , $ number , $ category ) {
510- return _dcngettext ($ domain , $ single , $ plural , $ number , $ category );
510+ function dcngettext ($ domain , $ singular , $ plural , $ number , $ category ) {
511+ return _dcngettext ($ domain , $ singular , $ plural , $ number , $ category );
511512 }
512513 function pgettext ($ context , $ msgid ) {
513514 return _pgettext ($ context , $ msgid );
514515 }
515- function npgettext ($ context , $ single , $ plural , $ number ) {
516- return _npgettext ($ context , $ single , $ plural , $ number );
516+ function npgettext ($ context , $ singular , $ plural , $ number ) {
517+ return _npgettext ($ context , $ singular , $ plural , $ number );
517518 }
518519 function dpgettext ($ domain , $ context , $ msgid ) {
519520 return _dpgettext ($ domain , $ context , $ msgid );
520521 }
521- function dnpgettext ($ domain , $ context , $ single , $ plural , $ number ) {
522- return _dnpgettext ($ domain , $ context , $ single , $ plural , $ number );
522+ function dnpgettext ($ domain , $ context , $ singular , $ plural , $ number ) {
523+ return _dnpgettext ($ domain , $ context , $ singular , $ plural , $ number );
523524 }
524525 function dcpgettext ($ domain , $ context , $ msgid , $ category ) {
525526 return _dcpgettext ($ domain , $ context , $ msgid , $ category );
526527 }
527- function dcnpgettext ($ domain , $ context , $ single , $ plural ,
528+ function dcnpgettext ($ domain , $ context , $ singular , $ plural ,
528529 $ number , $ category ) {
529- return _dcnpgettext ($ domain , $ context , $ single , $ plural ,
530+ return _dcnpgettext ($ domain , $ context , $ singular , $ plural ,
530531 $ number , $ category );
531532 }
532533}
0 commit comments