本文整理汇总了PHP中LocaleUtil::acceptLocales方法的典型用法代码示例。如果您正苦于以下问题:PHP LocaleUtil::acceptLocales方法的具体用法?PHP LocaleUtil::acceptLocales怎么用?PHP LocaleUtil::acceptLocales使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocaleUtil
的用法示例。
在下文中一共展示了LocaleUtil::acceptLocales方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initLanguage
protected function initLanguage()
{
$bIsMultilingual = Settings::getSetting('general', 'multilingual', true);
if ($bIsMultilingual && self::hasNextPathItem() && LanguageQuery::languageIsActive(self::peekNextPathItem(), true)) {
$oLanguage = LanguageQuery::create()->filterByPathPrefix(self::usePath())->findOne();
Session::getSession()->setLanguage($oLanguage);
} else {
// If site is monolingual, try setting the session default as a shortcut
if ($bIsMultilingual) {
// If we’ve got a valid session language set (and it’s not just from the default), use that
if (Session::getSession()->hasAttribute(Session::SESSION_LANGUAGE_KEY) && LanguageQuery::languageIsActive(Session::language())) {
LinkUtil::redirectToLanguage();
}
// Otherwise, use the first of the user’s accept languages that is valid
foreach (LocaleUtil::acceptLocales() as $oAcceptLocale) {
if (LanguageQuery::languageIsActive($oAcceptLocale->language_id)) {
Session::getSession()->setLanguage($oAcceptLocale->language_id);
LinkUtil::redirectToLanguage();
}
}
// As a last resort, try, the default session language
Session::getSession()->resetAttribute(Session::SESSION_LANGUAGE_KEY);
if (LanguageQuery::languageIsActive(Session::language())) {
LinkUtil::redirectToLanguage();
}
} else {
if (LanguageQuery::languageIsActive(Session::language())) {
return;
} else {
Session::getSession()->resetAttribute(Session::SESSION_LANGUAGE_KEY);
if (LanguageQuery::languageIsActive(Session::language())) {
return;
}
}
}
// If all fails, redirect to the admin manager, where new languages can be created/activated
LinkUtil::redirectToManager(array('languages'), "AdminManager");
}
}