@@ -150,10 +150,11 @@ |
||
| 150 | 150 | */ |
| 151 | 151 | public static function extract_plural_forms_header_from_po_header($header) |
| 152 | 152 | { |
| 153 | - if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) |
|
| 154 | - $expr = $regs[2]; |
|
| 155 | - else |
|
| 156 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 153 | + if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) { |
|
| 154 | + $expr = $regs[2]; |
|
| 155 | + } else { |
|
| 156 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 157 | + } |
|
| 157 | 158 | return $expr; |
| 158 | 159 | } |
| 159 | 160 | |
@@ -77,32 +77,45 @@ discard block |
||
| 77 | 77 | ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
| 78 | 78 | $locale, $matches)) { |
| 79 | 79 | |
| 80 | - if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
| 81 | - if (isset($matches["country"])) $country = $matches["country"]; |
|
| 82 | - if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
| 83 | - if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
| 80 | + if (isset($matches["lang"])) { |
|
| 81 | + $lang = $matches["lang"]; |
|
| 82 | + } |
|
| 83 | + if (isset($matches["country"])) { |
|
| 84 | + $country = $matches["country"]; |
|
| 85 | + } |
|
| 86 | + if (isset($matches["charset"])) { |
|
| 87 | + $charset = $matches["charset"]; |
|
| 88 | + } |
|
| 89 | + if (isset($matches["modifier"])) { |
|
| 90 | + $modifier = $matches["modifier"]; |
|
| 91 | + } |
|
| 84 | 92 | |
| 85 | 93 | if ($modifier) { |
| 86 | 94 | if ($country) { |
| 87 | - if ($charset) |
|
| 88 | - array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 95 | + if ($charset) { |
|
| 96 | + array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 97 | + } |
|
| 89 | 98 | array_push($locale_names, "${lang}_$country@$modifier"); |
| 90 | - } elseif ($charset) |
|
| 91 | - array_push($locale_names, "${lang}.$charset@$modifier"); |
|
| 99 | + } elseif ($charset) { |
|
| 100 | + array_push($locale_names, "${lang}.$charset@$modifier"); |
|
| 101 | + } |
|
| 92 | 102 | array_push($locale_names, "$lang@$modifier"); |
| 93 | 103 | } |
| 94 | 104 | if ($country) { |
| 95 | - if ($charset) |
|
| 96 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
| 105 | + if ($charset) { |
|
| 106 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
| 107 | + } |
|
| 97 | 108 | array_push($locale_names, "${lang}_$country"); |
| 98 | - } elseif ($charset) |
|
| 99 | - array_push($locale_names, "${lang}.$charset"); |
|
| 109 | + } elseif ($charset) { |
|
| 110 | + array_push($locale_names, "${lang}.$charset"); |
|
| 111 | + } |
|
| 100 | 112 | array_push($locale_names, $lang); |
| 101 | 113 | } |
| 102 | 114 | |
| 103 | 115 | // If the locale name doesn't match POSIX style, just include it as-is. |
| 104 | - if (!in_array($locale, $locale_names)) |
|
| 105 | - array_push($locale_names, $locale); |
|
| 116 | + if (!in_array($locale, $locale_names)) { |
|
| 117 | + array_push($locale_names, $locale); |
|
| 118 | + } |
|
| 106 | 119 | } |
| 107 | 120 | return $locale_names; |
| 108 | 121 | } |
@@ -112,7 +125,9 @@ discard block |
||
| 112 | 125 | */ |
| 113 | 126 | function _get_reader($domain=null, $category=5) { |
| 114 | 127 | global $text_domains, $default_domain, $LC_CATEGORIES; |
| 115 | - if (!isset($domain)) $domain = $default_domain; |
|
| 128 | + if (!isset($domain)) { |
|
| 129 | + $domain = $default_domain; |
|
| 130 | + } |
|
| 116 | 131 | if (!isset($text_domains[$domain]->l10n)) { |
| 117 | 132 | // get the current locale |
| 118 | 133 | $locale = _setlocale(LC_MESSAGES, 0); |
@@ -152,8 +167,9 @@ discard block |
||
| 152 | 167 | */ |
| 153 | 168 | function _check_locale_and_function($function=false) { |
| 154 | 169 | global $EMULATEGETTEXT; |
| 155 | - if ($function and !function_exists($function)) |
|
| 156 | - return false; |
|
| 170 | + if ($function and !function_exists($function)) { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 157 | 173 | return !$EMULATEGETTEXT; |
| 158 | 174 | } |
| 159 | 175 | |
@@ -162,7 +178,9 @@ discard block |
||
| 162 | 178 | */ |
| 163 | 179 | function _get_codeset($domain=null) { |
| 164 | 180 | global $text_domains, $default_domain, $LC_CATEGORIES; |
| 165 | - if (!isset($domain)) $domain = $default_domain; |
|
| 181 | + if (!isset($domain)) { |
|
| 182 | + $domain = $default_domain; |
|
| 183 | + } |
|
| 166 | 184 | return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
| 167 | 185 | } |
| 168 | 186 | |
@@ -177,8 +195,7 @@ discard block |
||
| 177 | 195 | $target_encoding = _get_codeset(); |
| 178 | 196 | if ($source_encoding != $target_encoding) { |
| 179 | 197 | return mb_convert_encoding($text, $target_encoding, $source_encoding); |
| 180 | - } |
|
| 181 | - else { |
|
| 198 | + } else { |
|
| 182 | 199 | return $text; |
| 183 | 200 | } |
| 184 | 201 | } |
@@ -190,11 +207,13 @@ discard block |
||
| 190 | 207 | * Returns passed in $locale, or environment variable $LANG if $locale == ''. |
| 191 | 208 | */ |
| 192 | 209 | function _get_default_locale($locale) { |
| 193 | - if ($locale == '') // emulate variable support |
|
| 210 | + if ($locale == '') { |
|
| 211 | + // emulate variable support |
|
| 194 | 212 | return getenv('LANG'); |
| 195 | - else |
|
| 196 | - return $locale; |
|
| 197 | -} |
|
| 213 | + } else { |
|
| 214 | + return $locale; |
|
| 215 | + } |
|
| 216 | + } |
|
| 198 | 217 | |
| 199 | 218 | /** |
| 200 | 219 | * Sets a requested locale, if needed emulates it. |
@@ -202,12 +221,13 @@ discard block |
||
| 202 | 221 | function _setlocale($category, $locale) { |
| 203 | 222 | global $CURRENTLOCALE, $EMULATEGETTEXT; |
| 204 | 223 | if ($locale === 0) { // use === to differentiate between string "0" |
| 205 | - if ($CURRENTLOCALE != '') |
|
| 206 | - return $CURRENTLOCALE; |
|
| 207 | - else |
|
| 208 | - // obey LANG variable, maybe extend to support all of LC_* vars |
|
| 224 | + if ($CURRENTLOCALE != '') { |
|
| 225 | + return $CURRENTLOCALE; |
|
| 226 | + } else { |
|
| 227 | + // obey LANG variable, maybe extend to support all of LC_* vars |
|
| 209 | 228 | // even if we tried to read locale without setting it first |
| 210 | 229 | return _setlocale($category, $CURRENTLOCALE); |
| 230 | + } |
|
| 211 | 231 | } else { |
| 212 | 232 | if (function_exists('setlocale')) { |
| 213 | 233 | $ret = setlocale($category, $locale); |
@@ -241,11 +261,13 @@ discard block |
||
| 241 | 261 | global $text_domains; |
| 242 | 262 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
| 243 | 263 | if (DIRECTORY_SEPARATOR == '\\') { |
| 244 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
| 245 | - $path .= '\\'; |
|
| 264 | + if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') { |
|
| 265 | + $path .= '\\'; |
|
| 266 | + } |
|
| 246 | 267 | } else { |
| 247 | - if ($path[strlen($path)-1] != '/') |
|
| 248 | - $path .= '/'; |
|
| 268 | + if ($path[strlen($path)-1] != '/') { |
|
| 269 | + $path .= '/'; |
|
| 270 | + } |
|
| 249 | 271 | } |
| 250 | 272 | if (!array_key_exists($domain, $text_domains)) { |
| 251 | 273 | // Initialize an empty domain object. |
@@ -384,96 +406,126 @@ discard block |
||
| 384 | 406 | } |
| 385 | 407 | |
| 386 | 408 | function T_bindtextdomain($domain, $path) { |
| 387 | - if (_check_locale_and_function()) return bindtextdomain($domain, $path); |
|
| 388 | - else return _bindtextdomain($domain, $path); |
|
| 389 | -} |
|
| 409 | + if (_check_locale_and_function()) { |
|
| 410 | + return bindtextdomain($domain, $path); |
|
| 411 | + } else { |
|
| 412 | + return _bindtextdomain($domain, $path); |
|
| 413 | + } |
|
| 414 | + } |
|
| 390 | 415 | function T_bind_textdomain_codeset($domain, $codeset) { |
| 391 | 416 | // bind_textdomain_codeset is available only in PHP 4.2.0+ |
| 392 | - if (_check_locale_and_function('bind_textdomain_codeset')) |
|
| 393 | - return bind_textdomain_codeset($domain, $codeset); |
|
| 394 | - else return _bind_textdomain_codeset($domain, $codeset); |
|
| 395 | -} |
|
| 417 | + if (_check_locale_and_function('bind_textdomain_codeset')) { |
|
| 418 | + return bind_textdomain_codeset($domain, $codeset); |
|
| 419 | + } else { |
|
| 420 | + return _bind_textdomain_codeset($domain, $codeset); |
|
| 421 | + } |
|
| 422 | + } |
|
| 396 | 423 | function T_textdomain($domain) { |
| 397 | - if (_check_locale_and_function()) return textdomain($domain); |
|
| 398 | - else return _textdomain($domain); |
|
| 399 | -} |
|
| 424 | + if (_check_locale_and_function()) { |
|
| 425 | + return textdomain($domain); |
|
| 426 | + } else { |
|
| 427 | + return _textdomain($domain); |
|
| 428 | + } |
|
| 429 | + } |
|
| 400 | 430 | function T_gettext($msgid) { |
| 401 | - if (_check_locale_and_function()) return gettext($msgid); |
|
| 402 | - else return _gettext($msgid); |
|
| 403 | -} |
|
| 431 | + if (_check_locale_and_function()) { |
|
| 432 | + return gettext($msgid); |
|
| 433 | + } else { |
|
| 434 | + return _gettext($msgid); |
|
| 435 | + } |
|
| 436 | + } |
|
| 404 | 437 | function T_($msgid) { |
| 405 | - if (_check_locale_and_function()) return _($msgid); |
|
| 438 | + if (_check_locale_and_function()) { |
|
| 439 | + return _($msgid); |
|
| 440 | + } |
|
| 406 | 441 | return __($msgid); |
| 407 | 442 | } |
| 408 | 443 | function T_ngettext($singular, $plural, $number) { |
| 409 | - if (_check_locale_and_function()) |
|
| 410 | - return ngettext($singular, $plural, $number); |
|
| 411 | - else return _ngettext($singular, $plural, $number); |
|
| 412 | -} |
|
| 444 | + if (_check_locale_and_function()) { |
|
| 445 | + return ngettext($singular, $plural, $number); |
|
| 446 | + } else { |
|
| 447 | + return _ngettext($singular, $plural, $number); |
|
| 448 | + } |
|
| 449 | + } |
|
| 413 | 450 | function T_dgettext($domain, $msgid) { |
| 414 | - if (_check_locale_and_function()) return dgettext($domain, $msgid); |
|
| 415 | - else return _dgettext($domain, $msgid); |
|
| 416 | -} |
|
| 451 | + if (_check_locale_and_function()) { |
|
| 452 | + return dgettext($domain, $msgid); |
|
| 453 | + } else { |
|
| 454 | + return _dgettext($domain, $msgid); |
|
| 455 | + } |
|
| 456 | + } |
|
| 417 | 457 | function T_dngettext($domain, $singular, $plural, $number) { |
| 418 | - if (_check_locale_and_function()) |
|
| 419 | - return dngettext($domain, $singular, $plural, $number); |
|
| 420 | - else return _dngettext($domain, $singular, $plural, $number); |
|
| 421 | -} |
|
| 458 | + if (_check_locale_and_function()) { |
|
| 459 | + return dngettext($domain, $singular, $plural, $number); |
|
| 460 | + } else { |
|
| 461 | + return _dngettext($domain, $singular, $plural, $number); |
|
| 462 | + } |
|
| 463 | + } |
|
| 422 | 464 | function T_dcgettext($domain, $msgid, $category) { |
| 423 | - if (_check_locale_and_function()) |
|
| 424 | - return dcgettext($domain, $msgid, $category); |
|
| 425 | - else return _dcgettext($domain, $msgid, $category); |
|
| 426 | -} |
|
| 465 | + if (_check_locale_and_function()) { |
|
| 466 | + return dcgettext($domain, $msgid, $category); |
|
| 467 | + } else { |
|
| 468 | + return _dcgettext($domain, $msgid, $category); |
|
| 469 | + } |
|
| 470 | + } |
|
| 427 | 471 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
| 428 | - if (_check_locale_and_function()) |
|
| 429 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
| 430 | - else return _dcngettext($domain, $singular, $plural, $number, $category); |
|
| 431 | -} |
|
| 472 | + if (_check_locale_and_function()) { |
|
| 473 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
| 474 | + } else { |
|
| 475 | + return _dcngettext($domain, $singular, $plural, $number, $category); |
|
| 476 | + } |
|
| 477 | + } |
|
| 432 | 478 | |
| 433 | 479 | function T_pgettext($context, $msgid) { |
| 434 | - if (_check_locale_and_function('pgettext')) |
|
| 435 | - return pgettext($context, $msgid); |
|
| 436 | - else |
|
| 437 | - return _pgettext($context, $msgid); |
|
| 438 | -} |
|
| 480 | + if (_check_locale_and_function('pgettext')) { |
|
| 481 | + return pgettext($context, $msgid); |
|
| 482 | + } else { |
|
| 483 | + return _pgettext($context, $msgid); |
|
| 484 | + } |
|
| 485 | + } |
|
| 439 | 486 | |
| 440 | 487 | function T_dpgettext($domain, $context, $msgid) { |
| 441 | - if (_check_locale_and_function('dpgettext')) |
|
| 442 | - return dpgettext($domain, $context, $msgid); |
|
| 443 | - else |
|
| 444 | - return _dpgettext($domain, $context, $msgid); |
|
| 445 | -} |
|
| 488 | + if (_check_locale_and_function('dpgettext')) { |
|
| 489 | + return dpgettext($domain, $context, $msgid); |
|
| 490 | + } else { |
|
| 491 | + return _dpgettext($domain, $context, $msgid); |
|
| 492 | + } |
|
| 493 | + } |
|
| 446 | 494 | |
| 447 | 495 | function T_dcpgettext($domain, $context, $msgid, $category) { |
| 448 | - if (_check_locale_and_function('dcpgettext')) |
|
| 449 | - return dcpgettext($domain, $context, $msgid, $category); |
|
| 450 | - else |
|
| 451 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
| 452 | -} |
|
| 496 | + if (_check_locale_and_function('dcpgettext')) { |
|
| 497 | + return dcpgettext($domain, $context, $msgid, $category); |
|
| 498 | + } else { |
|
| 499 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
| 500 | + } |
|
| 501 | + } |
|
| 453 | 502 | |
| 454 | 503 | function T_npgettext($context, $singular, $plural, $number) { |
| 455 | - if (_check_locale_and_function('npgettext')) |
|
| 456 | - return npgettext($context, $singular, $plural, $number); |
|
| 457 | - else |
|
| 458 | - return _npgettext($context, $singular, $plural, $number); |
|
| 459 | -} |
|
| 504 | + if (_check_locale_and_function('npgettext')) { |
|
| 505 | + return npgettext($context, $singular, $plural, $number); |
|
| 506 | + } else { |
|
| 507 | + return _npgettext($context, $singular, $plural, $number); |
|
| 508 | + } |
|
| 509 | + } |
|
| 460 | 510 | |
| 461 | 511 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
| 462 | - if (_check_locale_and_function('dnpgettext')) |
|
| 463 | - return dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 464 | - else |
|
| 465 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 466 | -} |
|
| 512 | + if (_check_locale_and_function('dnpgettext')) { |
|
| 513 | + return dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 514 | + } else { |
|
| 515 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 516 | + } |
|
| 517 | + } |
|
| 467 | 518 | |
| 468 | 519 | function T_dcnpgettext($domain, $context, $singular, $plural, |
| 469 | 520 | $number, $category) { |
| 470 | - if (_check_locale_and_function('dcnpgettext')) |
|
| 471 | - return dcnpgettext($domain, $context, $singular, |
|
| 521 | + if (_check_locale_and_function('dcnpgettext')) { |
|
| 522 | + return dcnpgettext($domain, $context, $singular, |
|
| 472 | 523 | $plural, $number, $category); |
| 473 | - else |
|
| 474 | - return _dcnpgettext($domain, $context, $singular, |
|
| 524 | + } else { |
|
| 525 | + return _dcnpgettext($domain, $context, $singular, |
|
| 475 | 526 | $plural, $number, $category); |
| 476 | -} |
|
| 527 | + } |
|
| 528 | + } |
|
| 477 | 529 | |
| 478 | 530 | |
| 479 | 531 | |