Example #1
0
 /**
  * Return the key name of the user's currently selected locale (default
  * is "en_US" for U.S. English).
  * @return string
  */
 function getLocale()
 {
     static $currentLocale;
     if (!isset($currentLocale)) {
         if (defined('SESSION_DISABLE_INIT') || !Config::getVar('general', 'installed')) {
             // If the locale is specified in the URL, allow
             // it to override. (Necessary when locale is
             // being set, as cookie will not yet be re-set)
             $locale = Request::getUserVar('setLocale');
             if (empty($locale) || !in_array($locale, array_keys(AppLocale::getSupportedLocales()))) {
                 $locale = Request::getCookieVar('currentLocale');
             }
         } else {
             $sessionManager =& SessionManager::getManager();
             $session =& $sessionManager->getUserSession();
             $locale = $session->getSessionVar('currentLocale');
             $journal =& Request::getJournal();
             $site =& Request::getSite();
             if (!isset($locale)) {
                 $locale = Request::getCookieVar('currentLocale');
             }
             if (isset($locale)) {
                 // Check if user-specified locale is supported
                 if ($journal != null) {
                     $locales =& $journal->getSupportedLocaleNames();
                 } else {
                     $locales =& $site->getSupportedLocaleNames();
                 }
                 if (!in_array($locale, array_keys($locales))) {
                     unset($locale);
                 }
             }
             if (!isset($locale)) {
                 // Use journal/site default
                 if ($journal != null) {
                     $locale = $journal->getPrimaryLocale();
                 }
                 if (!isset($locale)) {
                     $locale = $site->getPrimaryLocale();
                 }
             }
         }
         if (!AppLocale::isLocaleValid($locale)) {
             $locale = LOCALE_DEFAULT;
         }
         $currentLocale = $locale;
     }
     return $currentLocale;
 }