Open Journal Systems  3.3.0
PKPLocale.inc.php
1 <?php
2 
22 import('lib.pkp.classes.i18n.LocaleFile');
23 
24 if (!defined('LOCALE_REGISTRY_FILE')) {
25  define('LOCALE_REGISTRY_FILE', 'registry/locales.xml');
26 }
27 if (!defined('LOCALE_DEFAULT')) {
28  define('LOCALE_DEFAULT', Config::getVar('i18n', 'locale'));
29 }
30 if (!defined('LOCALE_ENCODING')) {
31  define('LOCALE_ENCODING', Config::getVar('i18n', 'client_charset'));
32 }
33 
34 define('MASTER_LOCALE', 'en_US');
35 
36 // Error types for locale checking.
37 // Note: Cannot use numeric symbols for the constants below because
38 // array_merge_recursive doesn't treat numeric keys nicely.
39 define('LOCALE_ERROR_MISSING_KEY', 'LOCALE_ERROR_MISSING_KEY');
40 define('LOCALE_ERROR_EXTRA_KEY', 'LOCALE_ERROR_EXTRA_KEY');
41 define('LOCALE_ERROR_DIFFERING_PARAMS', 'LOCALE_ERROR_DIFFERING_PARAMS');
42 define('LOCALE_ERROR_MISSING_FILE', 'LOCALE_ERROR_MISSING_FILE');
43 
44 define('EMAIL_ERROR_MISSING_EMAIL', 'EMAIL_ERROR_MISSING_EMAIL');
45 define('EMAIL_ERROR_EXTRA_EMAIL', 'EMAIL_ERROR_EXTRA_EMAIL');
46 define('EMAIL_ERROR_DIFFERING_PARAMS', 'EMAIL_ERROR_DIFFERING_PARAMS');
47 
48 // Shared locale components
49 define('LOCALE_COMPONENT_PKP_COMMON', 0x00000001);
50 define('LOCALE_COMPONENT_PKP_ADMIN', 0x00000002);
51 define('LOCALE_COMPONENT_PKP_INSTALLER', 0x00000003);
52 define('LOCALE_COMPONENT_PKP_MANAGER', 0x00000004);
53 define('LOCALE_COMPONENT_PKP_READER', 0x00000005);
54 define('LOCALE_COMPONENT_PKP_SUBMISSION', 0x00000006);
55 define('LOCALE_COMPONENT_PKP_USER', 0x00000007);
56 define('LOCALE_COMPONENT_PKP_GRID', 0x00000008);
57 define('LOCALE_COMPONENT_PKP_DEFAULT', 0x00000009);
58 define('LOCALE_COMPONENT_PKP_EDITOR', 0x0000000A);
59 define('LOCALE_COMPONENT_PKP_REVIEWER', 0x0000000B);
60 define('LOCALE_COMPONENT_PKP_API', 0x0000000C);
61 
62 // Application-specific locale components
63 define('LOCALE_COMPONENT_APP_COMMON', 0x00000100);
64 define('LOCALE_COMPONENT_APP_MANAGER', 0x00000101);
65 define('LOCALE_COMPONENT_APP_SUBMISSION', 0x00000102);
66 define('LOCALE_COMPONENT_APP_AUTHOR', 0x00000103);
67 define('LOCALE_COMPONENT_APP_EDITOR', 0x00000104);
68 define('LOCALE_COMPONENT_APP_ADMIN', 0x00000105);
69 define('LOCALE_COMPONENT_APP_DEFAULT', 0x00000106);
70 define('LOCALE_COMPONENT_APP_API', 0x00000107);
71 define('LOCALE_COMPONENT_APP_EMAIL', 0x00000108);
72 
73 class PKPLocale {
74  static $request;
75 
80  static function getSupportedLocales() {
81  static $supportedLocales;
82  if (!isset($supportedLocales)) {
83  if (defined('SESSION_DISABLE_INIT')) {
84  $supportedLocales = AppLocale::getAllLocales();
85  } elseif (($context = self::$request->getContext())) {
86  $supportedLocales = $context->getSupportedLocaleNames();
87  } else {
88  $site = self::$request->getSite();
89  $supportedLocales = $site->getSupportedLocaleNames();
90  }
91  }
92  return $supportedLocales;
93  }
94 
99  static function getSupportedFormLocales() {
100  static $supportedFormLocales;
101  if (!isset($supportedFormLocales)) {
102  if (defined('SESSION_DISABLE_INIT')) {
103  $supportedFormLocales = AppLocale::getAllLocales();
104  } elseif (($context = self::$request->getContext())) {
105  $supportedFormLocales = $context->getSupportedFormLocaleNames();
106  } else {
107  $site = self::$request->getSite();
108  $supportedFormLocales = $site->getSupportedLocaleNames();
109  }
110  }
111  return $supportedFormLocales;
112  }
113 
119  static function getLocale() {
120  static $currentLocale;
121  if (!isset($currentLocale)) {
122  if (defined('SESSION_DISABLE_INIT')) {
123  // If the locale is specified in the URL, allow
124  // it to override. (Necessary when locale is
125  // being set, as cookie will not yet be re-set)
126  $locale = self::$request->getUserVar('setLocale');
127  if (empty($locale) || !in_array($locale, array_keys(AppLocale::getSupportedLocales()))) $locale = self::$request->getCookieVar('currentLocale');
128  } else {
129  $sessionManager = SessionManager::getManager();
130  $session = $sessionManager->getUserSession();
131  $locale = self::$request->getUserVar('uiLocale');
132 
133  $context = self::$request->getContext();
134  $site = self::$request->getSite();
135 
136  if (!isset($locale)) {
137  $locale = $session->getSessionVar('currentLocale');
138  }
139 
140  if (!isset($locale)) {
141  $locale = self::$request->getCookieVar('currentLocale');
142  }
143 
144  if (isset($locale)) {
145  // Check if user-specified locale is supported
146  if ($context != null) {
147  $locales = $context->getSupportedLocaleNames();
148  } else {
149  $locales = $site->getSupportedLocaleNames();
150  }
151 
152  if (!in_array($locale, array_keys($locales))) {
153  unset($locale);
154  }
155  }
156 
157  if (!isset($locale)) {
158  // Use context/site default
159  if ($context != null) {
160  $locale = $context->getPrimaryLocale();
161  }
162 
163  if (!isset($locale)) {
164  $locale = $site->getPrimaryLocale();
165  }
166  }
167  }
168 
169  if (!AppLocale::isLocaleValid($locale)) {
170  $locale = LOCALE_DEFAULT;
171  }
172 
173  $currentLocale = $locale;
174  }
175  return $currentLocale;
176  }
177 
182  static function getLocalePrecedence() {
183  static $localePrecedence;
184  if (!isset($localePrecedence)) {
185  $localePrecedence = array(AppLocale::getLocale());
186 
187  $context = self::$request->getContext();
188  if ($context && !in_array($context->getPrimaryLocale(), $localePrecedence)) $localePrecedence[] = $context->getPrimaryLocale();
189 
190  $site = self::$request->getSite();
191  if ($site && !in_array($site->getPrimaryLocale(), $localePrecedence)) $localePrecedence[] = $site->getPrimaryLocale();
192  }
193  return $localePrecedence;
194  }
195 
200  static function getPrimaryLocale() {
201  static $locale;
202  if ($locale) return $locale;
203 
204  if (defined('SESSION_DISABLE_INIT')) return $locale = LOCALE_DEFAULT;
205 
206  $context = self::$request->getContext();
207 
208  if (isset($context)) {
209  $locale = $context->getPrimaryLocale();
210  }
211 
212  if (!isset($locale)) {
213  $site = self::$request->getSite();
214  $locale = $site->getPrimaryLocale();
215  }
216 
217  if (!isset($locale) || !AppLocale::isLocaleValid($locale)) {
218  $locale = LOCALE_DEFAULT;
219  }
220 
221  return $locale;
222  }
223 
229  static function &getLocaleFiles($locale = null) {
230  $localeFiles =& Registry::get('localeFiles', true, array());
231  if ($locale !== null) {
232  if (!isset($localeFiles[$locale])) $localeFiles[$locale] = array();
233  return $localeFiles[$locale];
234  }
235  return $localeFiles;
236  }
237 
243  public static function addOctothorpes($key) {
244  return '##' . htmlentities($key) . '##';
245  }
246 
257  static function translate($key, $params = array(), $locale = null, $missingKeyHandler = array(__CLASS__, 'addOctothorpes')) {
258  if (!isset($locale)) $locale = AppLocale::getLocale();
259  if (($key = trim($key)) == '') return '';
260 
261  $localeFiles =& AppLocale::getLocaleFiles($locale);
262  $value = '';
263  for ($i = count($localeFiles) - 1 ; $i >= 0 ; $i --) {
264  $value = $localeFiles[$i]->translate($key, $params);
265  if ($value !== null) return $value;
266  }
267 
268  // Add a missing key to the debug notes.
269  $notes =& Registry::get('system.debug.notes');
270  $notes[] = array('debug.notes.missingLocaleKey', array('key' => $key));
271 
272  if (!HookRegistry::call('PKPLocale::translate', array(&$key, &$params, &$locale, &$localeFiles, &$value))) {
273  // Add some octothorpes to missing keys to make them more obvious
274  return $missingKeyHandler($key);
275  } else {
276  return $value;
277  }
278  }
279 
284  static function initialize($request) {
285  self::$request = $request;
286 
287  // Use defaults if locale info unspecified.
288  $locale = AppLocale::getLocale();
289  setlocale(LC_ALL, $locale . '.' . LOCALE_ENCODING, $locale);
290  putenv("LC_ALL=$locale");
291 
292  AppLocale::registerLocaleFile($locale, "lib/pkp/locale/$locale/common.po");
293 
294  // Set site time zone
295  // Starting from PHP 5.3.0 PHP will throw an E_WARNING if the default
296  // time zone is not set and date/time functions are used
297  // http://pl.php.net/manual/en/function.date-default-timezone-set.php
298  $timeZone = self::getTimeZone();
299  date_default_timezone_set($timeZone);
300 
301  if (Config::getVar('general', 'installed')) {
302  // Set the time zone for DB
303  // Get the offset from UTC
304  $now = new DateTime();
305  $mins = $now->getOffset() / 60;
306  $sgn = ($mins < 0 ? -1 : 1);
307  $mins = abs($mins);
308  $hrs = floor($mins / 60);
309  $mins -= $hrs * 60;
310  $offset = sprintf('%+d:%02d', $hrs*$sgn, $mins);
311 
312  $conn = DBConnection::getInstance();
313  $dbconn =& $conn->getDBConn();
314  switch($conn->getDriver()) {
315  case 'mysql':
316  case 'mysqli':
317  $dbconn->execute('SET time_zone = \''.$offset.'\'');
318  break;
319  case 'postgres':
320  case 'postgres64':
321  case 'postgres7':
322  case 'postgres8':
323  case 'postgres9':
324  $dbconn->execute('SET TIME ZONE INTERVAL \''.$offset.'\' HOUR TO MINUTE');
325  break;
326  default: assert(false);
327  }
328  }
329  }
330 
337  static function makeComponentMap($locale) {
338  $baseDir = "lib/pkp/locale/$locale/";
339 
340  return array(
341  LOCALE_COMPONENT_PKP_COMMON => $baseDir . 'common.po',
342  LOCALE_COMPONENT_PKP_ADMIN => $baseDir . 'admin.po',
343  LOCALE_COMPONENT_PKP_INSTALLER => $baseDir . 'installer.po',
344  LOCALE_COMPONENT_PKP_MANAGER => $baseDir . 'manager.po',
345  LOCALE_COMPONENT_PKP_READER => $baseDir . 'reader.po',
346  LOCALE_COMPONENT_PKP_SUBMISSION => $baseDir . 'submission.po',
347  LOCALE_COMPONENT_PKP_EDITOR => $baseDir . 'editor.po',
348  LOCALE_COMPONENT_PKP_REVIEWER => $baseDir . 'reviewer.po',
349  LOCALE_COMPONENT_PKP_USER => $baseDir . 'user.po',
350  LOCALE_COMPONENT_PKP_GRID => $baseDir . 'grid.po',
351  LOCALE_COMPONENT_PKP_DEFAULT => $baseDir . 'default.po',
352  LOCALE_COMPONENT_PKP_API => $baseDir . 'api.po',
353  );
354  }
355 
361  static function getFilenameComponentMap($locale) {
362  $filenameComponentMap =& Registry::get('localeFilenameComponentMap', true, array());
363  if (!isset($filenameComponentMap[$locale])) {
364  $filenameComponentMap[$locale] = AppLocale::makeComponentMap($locale);
365  }
366  return $filenameComponentMap[$locale];
367  }
368 
374  static function requireComponents() {
375  $params = func_get_args();
376 
377  $paramCount = count($params);
378  if ($paramCount === 0) return;
379 
380  // Get the locale
381  $lastParam = $params[$paramCount-1];
382  if (is_string($lastParam)) {
383  $locale = $lastParam;
384  $paramCount--;
385  } else {
386  $locale = AppLocale::getLocale();
387  }
388 
389  // Backwards compatibility: the list used to be supplied
390  // as an array in the first parameter.
391  if (is_array($params[0])) {
392  $params = $params[0];
393  $paramCount = count($params);
394  }
395 
396  // Go through and make sure each component is loaded if valid.
397  $loadedComponents =& Registry::get('loadedLocaleComponents', true, array());
398  $filenameComponentMap = AppLocale::getFilenameComponentMap($locale);
399  for ($i=0; $i<$paramCount; $i++) {
400  $component = $params[$i];
401 
402  // Don't load components twice
403  if (isset($loadedComponents[$locale][$component])) continue;
404 
405  // Validate component
406  if (!isset($filenameComponentMap[$component])) {
407  fatalError('Unknown locale component ' . $component);
408  }
409 
410  $filename = $filenameComponentMap[$component];
411  AppLocale::registerLocaleFile($locale, $filename);
412  $loadedComponents[$locale][$component] = true;
413  }
414  }
415 
423  static function registerLocaleFile ($locale, $filename, $addToTop = false) {
424  $localeFiles =& AppLocale::getLocaleFiles($locale);
425  $localeFile = new LocaleFile($locale, $filename);
426 
427  if (!HookRegistry::call('PKPLocale::registerLocaleFile::isValidLocaleFile', array(&$localeFile))) {
428  if (!$localeFile->isValid()) return null;
429  }
430  if ($addToTop) {
431  // Work-around: unshift by reference.
432  array_unshift($localeFiles, '');
433  $localeFiles[0] =& $localeFile;
434  } else {
435  $localeFiles[] =& $localeFile;
436  }
437  HookRegistry::call('PKPLocale::registerLocaleFile', array(&$locale, &$filename, &$addToTop));
438  return $localeFile;
439  }
440 
446  static function getLocaleStyleSheet($locale) {
448  if (isset($contents[$locale]['stylesheet'])) {
449  return $contents[$locale]['stylesheet'];
450  }
451  return null;
452  }
453 
465  static function getLocaleDirection($locale) {
467  if (isset($contents[$locale]['direction'])) {
468  return $contents[$locale]['direction'];
469  }
470  return 'ltr';
471  }
472 
478  static function isLocaleComplete($locale) {
480  if (!isset($contents[$locale])) return false;
481  if (isset($contents[$locale]['complete']) && $contents[$locale]['complete'] == 'false') {
482  return false;
483  }
484  return true;
485  }
486 
492  static function isLocaleWithFamilyFirst($locale) {
494  if (isset($contents[$locale]) && isset($contents[$locale]['familyFirst']) && $contents[$locale]['familyFirst'] == 'true') {
495  return true;
496  }
497  return false;
498  }
499 
505  static function isLocaleValid($locale) {
506  if (empty($locale)) return false;
507  // variants can be composed of five to eight letters, or of four characters starting with a digit
508  if (!preg_match('/^[a-z][a-z]_[A-Z][A-Z](@([A-Za-z0-9]{5,8}|\d[A-Za-z0-9]{3}))?$/', $locale)) return false;
509  if (file_exists('locale/' . $locale)) return true;
510  return false;
511  }
512 
518  static function &loadLocaleList($filename) {
519  $xmlDao = new XMLDAO();
520  $data = $xmlDao->parseStruct($filename, array('locale'));
521  $allLocales = array();
522 
523  // Build array with ($localKey => $localeName)
524  if (isset($data['locale'])) {
525  foreach ($data['locale'] as $localeData) {
526  $allLocales[$localeData['attributes']['key']] = $localeData['attributes'];
527  }
528  }
529 
530  return $allLocales;
531  }
532 
537  static function &getAllLocales() {
538  $rawContents =& AppLocale::_getAllLocalesCacheContent();
539  $allLocales = array();
540 
541  foreach ($rawContents as $locale => $contents) {
542  $allLocales[$locale] = $contents['name'];
543  }
544 
545  // if client encoding is set to iso-8859-1, transcode locales from utf8
546  if (LOCALE_ENCODING == "iso-8859-1") {
547  $allLocales = array_map('utf8_decode', $allLocales);
548  }
549 
550  return $allLocales;
551  }
552 
557  static function installLocale($locale) {
558  // Install default locale-specific data
559  import('lib.pkp.classes.db.DBDataXMLParser');
560 
561  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */
562  AppLocale::requireComponents(LOCALE_COMPONENT_APP_EMAIL, $locale);
563  $emailTemplateDao->installEmailTemplateLocaleData($emailTemplateDao->getMainEmailTemplatesFilename(), array($locale));
564 
565  // Load all plugins so they can add locale data if needed
566  $categories = PluginRegistry::getCategories();
567  foreach ($categories as $category) {
568  PluginRegistry::loadCategory($category);
569  }
570  HookRegistry::call('PKPLocale::installLocale', array(&$locale));
571  }
572 
577  static function uninstallLocale($locale) {
578  // Delete locale-specific data
579  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */
580  $emailTemplateDao->deleteEmailTemplatesByLocale($locale);
581  $emailTemplateDao->deleteDefaultEmailTemplatesByLocale($locale);
582  }
583 
588  static function reloadLocale($locale) {
590  AppLocale::installLocale($locale);
591  }
592 
599  static function getParameterNames($source) {
600  $matches = null;
601  PKPString::regexp_match_all('/({\$[^}]+})/' /* '/{\$[^}]+})/' */, $source, $matches);
602  array_shift($matches); // Knock the top element off the array
603  if (isset($matches[0])) return $matches[0];
604  return array();
605  }
606 
614  static function get3LetterFrom2LetterIsoLanguage($iso2Letter) {
615  assert(strlen($iso2Letter) == 2);
617  foreach($locales as $locale => $localeData) {
618  if (substr($locale, 0, 2) == $iso2Letter) {
619  assert(isset($localeData['iso639-2b']));
620  return $localeData['iso639-2b'];
621  }
622  }
623  return null;
624  }
625 
633  static function get2LetterFrom3LetterIsoLanguage($iso3Letter) {
634  assert(strlen($iso3Letter) == 3);
636  foreach($locales as $locale => $localeData) {
637  assert(isset($localeData['iso639-2b']));
638  if ($localeData['iso639-2b'] == $iso3Letter) {
639  return substr($locale, 0, 2);
640  }
641  }
642  return null;
643  }
644 
651  static function get3LetterIsoFromLocale($locale) {
652  assert(strlen($locale) >= 5);
653  $iso2Letter = substr($locale, 0, 2);
655  }
656 
671  static function getLocaleFrom3LetterIso($iso3Letter) {
672  assert(strlen($iso3Letter) == 3);
673  $primaryLocale = AppLocale::getPrimaryLocale();
674 
675  $localeCandidates = array();
677  foreach($locales as $locale => $localeData) {
678  assert(isset($localeData['iso639-2b']));
679  if ($localeData['iso639-2b'] == $iso3Letter) {
680  if ($locale == $primaryLocale) {
681  // In case of ambiguity the primary locale
682  // overrides all other options so we're done.
683  return $primaryLocale;
684  }
685  $localeCandidates[] = $locale;
686  }
687  }
688 
689  // Return null if we found no candidate locale.
690  if (empty($localeCandidates)) return null;
691 
692  if (count($localeCandidates) > 1) {
693  // Check whether one of the candidate locales
694  // is a supported locale. If so choose the first
695  // supported locale.
696  $supportedLocales = AppLocale::getSupportedLocales();
697  foreach($supportedLocales as $supportedLocale => $localeName) {
698  if (in_array($supportedLocale, $localeCandidates)) return $supportedLocale;
699  }
700  }
701 
702  // If there is only one candidate (or if we were
703  // unable to disambiguate) then return the unique
704  // (first) candidate found.
705  return array_shift($localeCandidates);
706  }
707 
714  static function getIso3FromIso1($iso1) {
715  assert(strlen($iso1) == 2);
717  foreach($locales as $locale => $localeData) {
718  if (substr($locale, 0, 2) == $iso1) {
719  assert(isset($localeData['iso639-3']));
720  return $localeData['iso639-3'];
721  }
722  }
723  return null;
724  }
725 
732  static function getIso1FromIso3($iso3) {
733  assert(strlen($iso3) == 3);
735  foreach($locales as $locale => $localeData) {
736  assert(isset($localeData['iso639-3']));
737  if ($localeData['iso639-3'] == $iso3) {
738  return substr($locale, 0, 2);
739  }
740  }
741  return null;
742  }
743 
750  static function getIso3FromLocale($locale) {
751  assert(strlen($locale) >= 5);
752  $iso1 = substr($locale, 0, 2);
753  return AppLocale::getIso3FromIso1($iso1);
754  }
755 
762  static function getIso1FromLocale($locale) {
763  assert(strlen($locale) >= 5);
764  return substr($locale, 0, 2);
765  }
766 
781  static function getLocaleFromIso3($iso3) {
782  assert(strlen($iso3) == 3);
783  $primaryLocale = AppLocale::getPrimaryLocale();
784 
785  $localeCandidates = array();
787  foreach($locales as $locale => $localeData) {
788  assert(isset($localeData['iso639-3']));
789  if ($localeData['iso639-3'] == $iso3) {
790  if ($locale == $primaryLocale) {
791  // In case of ambiguity the primary locale
792  // overrides all other options so we're done.
793  return $primaryLocale;
794  }
795  $localeCandidates[] = $locale;
796  }
797  }
798 
799  // Return null if we found no candidate locale.
800  if (empty($localeCandidates)) return null;
801 
802  if (count($localeCandidates) > 1) {
803  // Check whether one of the candidate locales
804  // is a supported locale. If so choose the first
805  // supported locale.
806  $supportedLocales = AppLocale::getSupportedLocales();
807  foreach($supportedLocales as $supportedLocale => $localeName) {
808  if (in_array($supportedLocale, $localeCandidates)) return $supportedLocale;
809  }
810  }
811 
812  // If there is only one candidate (or if we were
813  // unable to disambiguate) then return the unique
814  // (first) candidate found.
815  return array_shift($localeCandidates);
816  }
817 
818  //
819  // Private helper methods.
820  //
825  static function &_getAllLocalesCacheContent() {
826  static $contents = false;
827  if ($contents === false) {
828  $allLocalesCache =& AppLocale::_getAllLocalesCache();
829  $contents = $allLocalesCache->getContents();
830  }
831  return $contents;
832  }
833 
838  static function &_getAllLocalesCache() {
839  $cache =& Registry::get('allLocalesCache', true, null);
840  if ($cache === null) {
841  $cacheManager = CacheManager::getManager();
842  $cache = $cacheManager->getFileCache(
843  'locale', 'list',
844  array('AppLocale', '_allLocalesCacheMiss')
845  );
846 
847  // Check to see if the data is outdated
848  $cacheTime = $cache->getCacheTime();
849  if ($cacheTime !== null && $cacheTime < filemtime(LOCALE_REGISTRY_FILE)) {
850  $cache->flush();
851  }
852  }
853  return $cache;
854  }
855 
861  static function _allLocalesCacheMiss($cache, $id) {
862  $allLocales =& Registry::get('allLocales', true, null);
863  if ($allLocales === null) {
864  // Add a locale load to the debug notes.
865  $notes =& Registry::get('system.debug.notes');
866  $notes[] = array('debug.notes.localeListLoad', array('localeList' => LOCALE_REGISTRY_FILE));
867 
868  // Reload locale registry file
869  $allLocales = AppLocale::loadLocaleList(LOCALE_REGISTRY_FILE);
870  asort($allLocales);
871  $cache->setEntireCache($allLocales);
872  }
873  return null;
874  }
875 
880  static function getTimeZone() {
881  $timeZone = null;
882 
883  // Load the time zone from the configuration file
884  if ($timeZoneConfig = Config::getVar('general', 'time_zone')) {
885  $timeZoneDAO = DAORegistry::getDAO('TimeZoneDAO');
886  $timeZoneList = $timeZoneDAO->getTimeZones();
887  foreach ($timeZoneList as $timeZoneKey => $timeZoneName) {
888  if (in_array($timeZoneConfig, array($timeZoneKey, $timeZoneName))) {
889  $timeZone = $timeZoneKey;
890  break;
891  }
892  }
893  }
894 
895  // Fall back to the time zone set in php.ini
896  if (empty($timeZone)) $timeZone = ini_get('date.timezone');
897 
898  // Fall back to UTC
899  if (empty($timeZone)) $timeZone = 'UTC';
900 
901  return $timeZone;
902  }
903 }
904 
905 
923 function __($key, $params = array(), $locale = null, $missingKeyHandler = array('PKPLocale', 'addOctothorpes')) {
924  return AppLocale::translate($key, $params, $locale, $missingKeyHandler);
925 }
PKPLocale\getSupportedFormLocales
static getSupportedFormLocales()
Definition: PKPLocale.inc.php:99
PKPLocale\getLocaleStyleSheet
static getLocaleStyleSheet($locale)
Definition: PKPLocale.inc.php:446
XMLDAO
Operations for retrieving and modifying objects from an XML data source.
Definition: XMLDAO.inc.php:19
PKPLocale\getAllLocales
static & getAllLocales()
Definition: PKPLocale.inc.php:537
SessionManager\getManager
static getManager()
Definition: SessionManager.inc.php:124
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
PKPLocale\$request
static $request
Definition: PKPLocale.inc.php:74
LocaleFile
Abstraction of a locale file.
Definition: LocaleFile.inc.php:17
PKPLocale\getLocale
static getLocale()
Definition: PKPLocale.inc.php:119
PKPLocale\uninstallLocale
static uninstallLocale($locale)
Definition: PKPLocale.inc.php:577
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PKPString\regexp_match_all
static regexp_match_all($pattern, $subject, &$matches)
Definition: PKPString.inc.php:267
AppLocale\registerLocaleFile
static registerLocaleFile($locale, $filename, $addToTop=false)
Definition: env1/MockAppLocale.inc.php:48
PKPLocale\translate
static translate($key, $params=array(), $locale=null, $missingKeyHandler=array(__CLASS__, 'addOctothorpes'))
Definition: PKPLocale.inc.php:257
PKPLocale\get3LetterIsoFromLocale
static get3LetterIsoFromLocale($locale)
Definition: PKPLocale.inc.php:651
PKPLocale\isLocaleComplete
static isLocaleComplete($locale)
Definition: PKPLocale.inc.php:478
PKPLocale\getPrimaryLocale
static getPrimaryLocale()
Definition: PKPLocale.inc.php:200
PKPLocale\getSupportedLocales
static getSupportedLocales()
Definition: PKPLocale.inc.php:80
PKPLocale\getIso3FromLocale
static getIso3FromLocale($locale)
Definition: PKPLocale.inc.php:750
AppLocale\getPrimaryLocale
static getPrimaryLocale()
Definition: env1/MockAppLocale.inc.php:95
PKPLocale\getTimeZone
static getTimeZone()
Definition: PKPLocale.inc.php:880
PKPLocale\reloadLocale
static reloadLocale($locale)
Definition: PKPLocale.inc.php:588
PKPLocale\getLocaleDirection
static getLocaleDirection($locale)
Definition: PKPLocale.inc.php:465
PKPLocale\initialize
static initialize($request)
Definition: PKPLocale.inc.php:284
PKPLocale\getLocaleFromIso3
static getLocaleFromIso3($iso3)
Definition: PKPLocale.inc.php:781
PKPLocale\getIso1FromIso3
static getIso1FromIso3($iso3)
Definition: PKPLocale.inc.php:732
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
PKPLocale
Provides methods for loading locale data and translating strings identified by unique keys.
Definition: PKPLocale.inc.php:73
PKPLocale\getLocalePrecedence
static getLocalePrecedence()
Definition: PKPLocale.inc.php:182
PKPLocale\getLocaleFrom3LetterIso
static getLocaleFrom3LetterIso($iso3Letter)
Definition: PKPLocale.inc.php:671
PKPLocale\getParameterNames
static getParameterNames($source)
Definition: PKPLocale.inc.php:599
PKPLocale\get3LetterFrom2LetterIsoLanguage
static get3LetterFrom2LetterIsoLanguage($iso2Letter)
Definition: PKPLocale.inc.php:614
AppLocale\translate
static translate($key, $params=array(), $locale=null, $missingKeyHandler=array())
Definition: env1/MockAppLocale.inc.php:75
PKPLocale\getIso1FromLocale
static getIso1FromLocale($locale)
Definition: PKPLocale.inc.php:762
CacheManager\getManager
static getManager()
Definition: CacheManager.inc.php:27
Registry\get
static & get($key, $createIfEmpty=false, $createWithDefault=null)
Definition: Registry.inc.php:35
Config\getVar
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
PKPLocale\_allLocalesCacheMiss
static _allLocalesCacheMiss($cache, $id)
Definition: PKPLocale.inc.php:861
PKPLocale\registerLocaleFile
static registerLocaleFile($locale, $filename, $addToTop=false)
Definition: PKPLocale.inc.php:423
PKPLocale\isLocaleWithFamilyFirst
static isLocaleWithFamilyFirst($locale)
Definition: PKPLocale.inc.php:492
AppLocale\getSupportedLocales
static getSupportedLocales()
Definition: env1/MockAppLocale.inc.php:116
PKPLocale\getIso3FromIso1
static getIso3FromIso1($iso1)
Definition: PKPLocale.inc.php:714
PKPLocale\_getAllLocalesCache
static & _getAllLocalesCache()
Definition: PKPLocale.inc.php:838
PluginRegistry\getCategories
static getCategories()
Definition: PluginRegistry.inc.php:196
PKPLocale\installLocale
static installLocale($locale)
Definition: PKPLocale.inc.php:557
PKPLocale\get2LetterFrom3LetterIsoLanguage
static get2LetterFrom3LetterIsoLanguage($iso3Letter)
Definition: PKPLocale.inc.php:633
fatalError
if(!function_exists('import')) fatalError($reason)
Definition: functions.inc.php:32
PKPLocale\loadLocaleList
static & loadLocaleList($filename)
Definition: PKPLocale.inc.php:518
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
PKPLocale\addOctothorpes
static addOctothorpes($key)
Definition: PKPLocale.inc.php:243
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40
PKPLocale\isLocaleValid
static isLocaleValid($locale)
Definition: PKPLocale.inc.php:505
DBConnection\getInstance
static getInstance($setInstance=null)
Definition: DBConnection.inc.php:241
PKPLocale\_getAllLocalesCacheContent
static & _getAllLocalesCacheContent()
Definition: PKPLocale.inc.php:825
PKPLocale\getLocaleFiles
static & getLocaleFiles($locale=null)
Definition: PKPLocale.inc.php:229