Beispiel #1
0
 /**
  * Finds the proper locale based on the input
  * Checks if it exists, degrades it when necessary
  * Detects registry locale and when all fails tries to detect a automatic locale
  * Returns the found locale as string
  *
  * @param string $locale
  * @throws JO_Locale_Exception When the given locale is no locale or the autodetection fails
  * @return string
  */
 public static function findLocale($locale = null)
 {
     if ($locale === null) {
         require_once 'JO/Registry.php';
         if (JO_Registry::isRegistered('JO_Locale')) {
             $locale = JO_Registry::get('JO_Locale');
         }
     }
     if ($locale === null) {
         $locale = new JO_Locale();
     }
     if (!JO_Locale::isLocale($locale, true, false)) {
         if (!JO_Locale::isLocale($locale, false, false)) {
             $locale = JO_Locale::getLocaleToTerritory($locale);
             if (empty($locale)) {
                 require_once 'JO/Exception.php';
                 throw new JO_Exception("The locale '{$locale}' is no known locale");
             }
         } else {
             $locale = new JO_Locale($locale);
         }
     }
     $locale = self::_prepareLocale($locale);
     return $locale;
 }