本文整理汇总了PHP中Translator::setLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::setLocale方法的具体用法?PHP Translator::setLocale怎么用?PHP Translator::setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translator
的用法示例。
在下文中一共展示了Translator::setLocale方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTranslateWithAlternateDefaultLocale
/**
* @covers phpDocumentor\Translator\Translator::addTranslations
* @covers phpDocumentor\Translator\Translator::translate
*/
public function testTranslateWithAlternateDefaultLocale()
{
$this->fixture->addTranslations($this->filename, self::LOCALE_NL);
$this->fixture->setLocale(self::LOCALE_NL);
$this->assertEquals(self::TEST_VALUE, $this->fixture->translate(self::TEST_KEY));
}
示例2: initLocale
public function initLocale()
{
// Load from persist
$locale = $this->getPersist(static::PERSIST_LOCALE);
if ($locale) {
$this->locale = $locale;
// Detect via browser
} elseif (!$this->locale) {
$auto = 'en';
$acceptedLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
$matched = preg_match_all('/([a-z]{2,8}(-[a-z]{2,8})?)\\s*(;\\s*q\\s*=\\s*(1|0\\.[0-9]+))?/i', $acceptedLanguage, $matches);
if ($matched) {
$languageList = $this->getLanguages();
foreach ($matches[1] as $language) {
$canonized = strtolower($language);
if (isset($languageList[$canonized])) {
$auto = $canonized;
break;
} else {
$pos = strpos($language, '-');
if (false !== $pos) {
$canonized = substr($language, 0, $pos);
if (isset($languageList[$canonized])) {
$auto = $canonized;
break;
}
}
}
}
}
$this->setLocale($auto);
}
$charset = $this->getPersist(static::PERSIST_CHARSET);
if ($charset) {
$this->charset = $charset;
}
Translator::setPath($this->getRoot() . '/locale');
Translator::setLocale($this->locale);
Translator::loadDomain('default');
}