/** * Match locale to code at end of string. * @param string e.g. "something-fr_FR" * @return LocoLocale */ function loco_locale_resolve($s) { $lc = ''; $cc = ''; if (preg_match('/(?:^|\\W)([a-z]{2})(?:(?:-|_)([a-z]{2}))?$/i', $s, $r)) { $lc = strtolower($r[1]); if (isset($r[2])) { $cc = strtoupper($r[2]); } } return LocoLocale::init($lc, $cc); }
/** * Match locale to code at end of string. * @param string e.g. "something-fr_FR" * @return LocoLocale */ function loco_locale_resolve($s) { $lc = ''; $cc = ''; if (preg_match('/(?:^|\\W)([a-z]{2,3})(?:(?:-|_)([a-z]{2}))?$/i', $s, $r)) { $lc = strtolower($r[1]); if (isset($r[2])) { $cc = strtoupper($r[2]); // handle situation when short domain part looks like language if (!LocoLocale::is_known_language($lc) && LocoLocale::is_known_language($cc)) { $lc = strtolower($cc); $cc = ''; } } } return LocoLocale::init($lc, $cc); }
public function testPluralFormArrays() { // English - two forms $locale = LocoLocale::init('en', 'GB'); extract($locale->export()); $this->assertCount(2, $plurals); // Chinese - one form $locale = LocoLocale::init('zh', 'TW'); extract($locale->export()); $this->assertCount(1, $plurals); // Polish - three forms $locale = LocoLocale::init('pl', 'PL'); extract($locale->export()); $this->assertCount(3, $plurals); // Arabic - six forms $locale = LocoLocale::init('ar', 'AE'); extract($locale->export()); $this->assertCount(6, $plurals); }