示例#1
0
 public static function setLocale($locale_arg = NULL, $category = LC_ALL)
 {
     Debug::Text('Generated/Passed In Locale: ' . $locale_arg, __FILE__, __LINE__, __METHOD__, 10);
     $locales = self::generateLocale($locale_arg);
     $locale = self::tryLocale($locales);
     unset($locales);
     Debug::Text('Attempting to set Locale(s) to: ' . $locale . ' Category: ' . $category . ' Current Locale: ' . self::getLocale(), __FILE__, __LINE__, __METHOD__, 10);
     if ($locale != self::getLocale() and in_array($category, array(LC_ALL, LC_MONETARY, LC_NUMERIC))) {
         Debug::Text('Setting currency/numeric Locale to: ' . $locale, __FILE__, __LINE__, __METHOD__, 10);
         //if ( self::getLocaleHandler()->setLocale( $locale, $category ) != $locale ) {
         //Setting the locale in Windows can cause the locale names to not match at all, so check for FALSE
         if (self::getLocaleHandler()->setLocale($locale, $category) == FALSE) {
             Debug::Text('Failed setting currency/numeric locale: ' . $locale, __FILE__, __LINE__, __METHOD__, 10);
         }
     }
     if ($locale != self::getLocale() and in_array($category, array(LC_ALL, LC_MESSAGES))) {
         // We normalize locales to a single "standard" locale for each lang
         // to avoid having to maintain lots of mostly duplicate translation files
         // for each lang/country combination.
         $normal_locale = self::_normalizeLocale($locale);
         Debug::Text('Setting translator to normalized locale: ' . $normal_locale, __FILE__, __LINE__, __METHOD__, 10);
         if (self::getTranslationHandler()->setLang($normal_locale) === FALSE) {
             //Fall back on non-normalized locale
             Debug::Text('Failed setting translator normalized locale: ' . $normal_locale . ' Falling back to: ' . $locale, __FILE__, __LINE__, __METHOD__, 10);
             if (self::getTranslationHandler()->setLang($locale) === FALSE) {
                 Debug::Text('Failed setting translator locale: ' . $locale, __FILE__, __LINE__, __METHOD__, 10);
                 return FALSE;
             }
         }
     }
     self::$locale = $locale;
     self::$language = substr($locale, 0, 2);
     //save language here to avoid becoming out of sync.
     if ($category == LC_ALL) {
         if (self::$master_locale == NULL) {
             self::$master_locale = $locale;
         }
     }
     Debug::Text('Set Master Locale To: ' . $locale, __FILE__, __LINE__, __METHOD__, 10);
     return TRUE;
 }