Пример #1
0
 public function getSessionDefaultLocale()
 {
     // they have a language in a certain session going already
     if (isset($_SESSION['DEFAULT_LOCALE'])) {
         return $_SESSION['DEFAULT_LOCALE'];
     }
     // if they've specified their own default locale to remember
     if (isset($_COOKIE['DEFAULT_LOCALE'])) {
         return $_COOKIE['DEFAULT_LOCALE'];
     }
     if (User::isLoggedIn()) {
         $u = new User();
         $userDefaultLanguage = $u->getUserDefaultLanguage();
         if ($userDefaultLanguage != '') {
             if (is_object(MultilingualSection::getByLocale($userDefaultLanguage)) || $userDefaultLanguage == 'en_US' && Page::getCurrentPage()->cID != 1) {
                 return $userDefaultLanguage;
             }
         }
     }
     $pkg = Package::getByHandle('multilingual');
     //
     // This could set the cookie here but it does not.
     // If something wants to set the default language it should probably do that outside of here.
     //
     if ($pkg->config('TRY_BROWSER_LANGUAGE')) {
         Loader::model('section', 'multilingual');
         Loader::library('3rdparty/Zend/Locale');
         $locale = new Zend_Locale();
         if (is_object(MultilingualSection::getByLocale((string) $locale))) {
             return (string) $locale;
         } else {
             $section = MultilingualSection::getByLanguage((string) $locale->getLanguage());
             if (is_object($section)) {
                 return (string) $section->getLocale();
             }
         }
     }
     return $pkg->config('DEFAULT_LANGUAGE');
 }