Exemple #1
0
 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");
     }
 }