本文整理匯總了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");
}
}