Ejemplo n.º 1
0
 /**
  * Sets the locale and/or lang code
  * @return boolean
  */
 public static function setLocale($code, $lang = null)
 {
     if (!self::$isInit) {
         self::init();
     }
     // load locale general settings
     $locale =& self::$locale;
     $config =& self::$config;
     $code = str_replace(array('/', '\\', '.'), '', strtolower(trim($code)));
     //sanitize code
     $config['site.locale'] = $code;
     $pth = $config['locale.path'] . str_replace('-', '/', $code) . '/';
     // locales are stored as {lang}/{country}
     if (is_file($pth . 'general.php') && (include_once $pth . 'general.php')) {
         $config['lang.path'] = $pth;
         if ($lang !== null) {
             $config['site.lang'] = $lang;
         } else {
             $config['site.lang'] = substr($code, 0, 2);
         }
         setlocale(LC_CTYPE, $locale['php.locale']);
         setlocale(LC_COLLATE, $locale['php.locale']);
         // setup locale date name - used instead of LC_TIME as it's reported to fail on some systems
         $locale['dt._eng_names'] = array('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december', 'jan', 'feb', 'mar', 'apr', 'may', 'june', 'july', 'aug', 'sept', 'oct', 'nov', 'dec', 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
         $locale['dt._locale_names'] = array_merge($locale['months.full'], $locale['months.short'], $locale['days.full'], $locale['days.short']);
         $locale = array_merge($locale, array_combine($locale['dt._eng_names'], $locale['dt._locale_names']));
         // combine names
         return self::$isLocaleLoaded = true;
     }
     return false;
 }