本文整理汇总了PHP中CLocale::getCanonicalID方法的典型用法代码示例。如果您正苦于以下问题:PHP CLocale::getCanonicalID方法的具体用法?PHP CLocale::getCanonicalID怎么用?PHP CLocale::getCanonicalID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CLocale
的用法示例。
在下文中一共展示了CLocale::getCanonicalID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPreferredAvailableLanguage
public function getPreferredAvailableLanguage()
{
$preferedLanguages = $this->getPreferredLanguages();
$languages = array_keys(Yii::app()->params['availableLanguages']);
foreach ($preferedLanguages as $preferredLanguage) {
foreach ($languages as $language) {
$preferredLanguage = CLocale::getCanonicalID($preferredLanguage);
if ($language === $preferredLanguage) {
return $language;
}
}
}
return false;
}
示例2: getPreferredLanguage
/**
* Returns the user preferred language.
* The returned language ID will be canonicalized using {@link CLocale::getCanonicalID}.
* This method returns false if the user does not have language preference.
* @return string the user preferred language.
*/
public function getPreferredLanguage()
{
if ($this->_preferredLanguage === null) {
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && ($n = preg_match_all('/([\\w\\-_]+)\\s*(;\\s*q\\s*=\\s*(\\d*\\.\\d*))?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches)) > 0) {
$languages = array();
for ($i = 0; $i < $n; ++$i) {
$languages[$matches[1][$i]] = empty($matches[3][$i]) ? 1.0 : floatval($matches[3][$i]);
}
arsort($languages);
foreach ($languages as $language => $pref) {
return $this->_preferredLanguage = CLocale::getCanonicalID($language);
}
}
return $this->_preferredLanguage = false;
}
return $this->_preferredLanguage;
}
示例3: getPreferredLanguage
public function getPreferredLanguage()
{
$preferredLanguages = $this->getPreferredLanguages();
return !empty($preferredLanguages) ? CLocale::getCanonicalID($preferredLanguages[0]) : false;
}
示例4: setLanguage
/**
* @param string $language the language that the source messages are written in.
*/
public function setLanguage($language)
{
$this->_language = CLocale::getCanonicalID($language);
}
示例5: getPreferredLanguage
public function getPreferredLanguage($languages = array())
{
$preferredLanguages = $this->getPreferredLanguages();
if (empty($languages)) {
return !empty($preferredLanguages) ? CLocale::getCanonicalID($preferredLanguages[0]) : false;
}
foreach ($preferredLanguages as $preferredLanguage) {
$preferredLanguage = CLocale::getCanonicalID($preferredLanguage);
foreach ($languages as $language) {
$language = CLocale::getCanonicalID($language);
// en_us==en_us, en==en_us, en_us==en
if ($language === $acceptedLanguage || strpos($acceptedLanguage, $language . '_') === 0 || strpos($language, $acceptedLanguage . '_') === 0) {
return $language;
}
}
}
return reset($languages);
}