classes/i18n/AppLocale.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 
00019 import('i18n.PKPLocale');
00020 
00021 define('LOCALE_COMPONENT_APPLICATION_COMMON',   0x00000101);
00022 define('LOCALE_COMPONENT_OCS_AUTHOR',     0x00000102);
00023 define('LOCALE_COMPONENT_OCS_DIRECTOR',      0x00000103);
00024 define('LOCALE_COMPONENT_OCS_MANAGER',    0x00000104);
00025 define('LOCALE_COMPONENT_OCS_ADMIN',      0x00000105);
00026 define('LOCALE_COMPONENT_OCS_DEFAULT',    0x00000106);
00027 
00028 class AppLocale extends PKPLocale {
00033    function getSupportedLocales() {
00034       static $supportedLocales;
00035       if (!isset($supportedLocales)) {
00036          if (defined('SESSION_DISABLE_INIT') || !Config::getVar('general', 'installed')) {
00037             $supportedLocales = AppLocale::getAllLocales();
00038          } elseif (($conference =& Request::getConference())) {
00039             $supportedLocales = $conference->getSupportedLocaleNames();
00040          } else {
00041             $site =& Request::getSite();
00042             $supportedLocales = $site->getSupportedLocaleNames();
00043          }
00044       }
00045       return $supportedLocales;
00046    }
00047 
00052    function getSupportedFormLocales() {
00053       static $supportedFormLocales;
00054       if (!isset($supportedFormLocales)) {
00055          if (defined('SESSION_DISABLE_INIT') || !Config::getVar('general', 'installed')) {
00056             $supportedFormLocales = AppLocale::getAllLocales();
00057          } elseif (($conference =& Request::getConference())) {
00058             $supportedFormLocales = $conference->getSupportedFormLocaleNames();
00059          } else {
00060             $site =& Request::getSite();
00061             $supportedFormLocales = $site->getSupportedLocaleNames();
00062          }
00063       }
00064       return $supportedFormLocales;
00065    }
00066 
00072    function getLocale() {
00073       static $currentLocale;
00074       if (!isset($currentLocale)) {
00075          if (defined('SESSION_DISABLE_INIT') || !Config::getVar('general', 'installed')) {
00076             // If the locale is specified in the URL, allow
00077             // it to override. (Necessary when locale is
00078             // being set, as cookie will not yet be re-set)
00079             $locale = Request::getUserVar('setLocale');
00080             if (empty($locale) || !in_array($locale, array_keys(AppLocale::getSupportedLocales()))) $locale = Request::getCookieVar('currentLocale');
00081          } else {
00082             $sessionManager =& SessionManager::getManager();
00083             $session =& $sessionManager->getUserSession();
00084             $locale = $session->getSessionVar('currentLocale');
00085 
00086             $conference =& Request::getConference();
00087             $site =& Request::getSite();
00088 
00089             if (!isset($locale)) {
00090                $locale = Request::getCookieVar('currentLocale');
00091             }
00092 
00093             if (isset($locale)) {
00094                // Check if user-specified locale is supported
00095                if ($conference != null) {
00096                   $locales =& $conference->getSupportedLocaleNames();
00097                } else {
00098                   $locales =& $site->getSupportedLocaleNames();
00099                }
00100 
00101                if (!in_array($locale, array_keys($locales))) {
00102                   unset($locale);
00103                }
00104             }
00105 
00106             if (!isset($locale)) {
00107                // Use conference/site default
00108                if ($conference != null) {
00109                   $locale = $conference->getPrimaryLocale();
00110                }
00111 
00112                if (!isset($locale)) {
00113                   $locale = $site->getPrimaryLocale();
00114                }
00115             }
00116          }
00117 
00118          if (!AppLocale::isLocaleValid($locale)) {
00119             $locale = LOCALE_DEFAULT;
00120          }
00121 
00122          $currentLocale = $locale;
00123       }
00124       return $currentLocale;
00125    }
00126 
00131    function getLocalePrecedence() {
00132       static $localePrecedence;
00133       if (!isset($localePrecedence)) {
00134          $localePrecedence = array(AppLocale::getLocale());
00135 
00136          $conference =& Request::getConference();
00137          if ($conference && !in_array($conference->getPrimaryLocale(), $localePrecedence)) $localePrecedence[] = $conference->getPrimaryLocale();
00138 
00139          $site =& Request::getSite();
00140          if ($site && !in_array($site->getPrimaryLocale(), $localePrecedence)) $localePrecedence[] = $site->getPrimaryLocale();
00141       }
00142       return $localePrecedence;
00143    }
00144 
00149    function getPrimaryLocale() {
00150       $conference =& Request::getConference();
00151 
00152       if (isset($conference)) {
00153          $locale = $conference->getPrimaryLocale();
00154       }
00155 
00156       if (!isset($locale)) {
00157          $site =& Request::getSite();
00158          $locale = $site->getPrimaryLocale();
00159       }
00160 
00161       if (!isset($locale) || !AppLocale::isLocaleValid($locale)) {
00162          $locale = LOCALE_DEFAULT;
00163       }
00164 
00165       return $locale;
00166    }
00167 
00173    function makeComponentMap($locale) {
00174       $componentMap = parent::makeComponentMap($locale);
00175       $baseDir = "locale/$locale/";
00176       $componentMap[LOCALE_COMPONENT_APPLICATION_COMMON] = $baseDir . 'locale.xml';
00177       $componentMap[LOCALE_COMPONENT_OCS_AUTHOR] = $baseDir . 'author.xml';
00178       $componentMap[LOCALE_COMPONENT_OCS_DIRECTOR] = $baseDir . 'director.xml';
00179       $componentMap[LOCALE_COMPONENT_OCS_MANAGER] = $baseDir . 'manager.xml';
00180       $componentMap[LOCALE_COMPONENT_OCS_ADMIN] = $baseDir . 'admin.xml';
00181       $componentMap[LOCALE_COMPONENT_OCS_DEFAULT] = $baseDir . 'default.xml';
00182       return $componentMap;
00183    }
00184 }
00185 
00186 if (!class_exists('Locale')) {
00187    class Locale extends AppLocale {
00188       // This is used for backwards compatibility (bug #5240)
00189    }
00190 }
00191 
00192 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7