コード例 #1
0
ファイル: Locale.php プロジェクト: jasmun/Noco100
 /**
  * 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 IfwPsn_Vendor_Zend_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 IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Registry.php';
         if (IfwPsn_Vendor_Zend_Registry::isRegistered('IfwPsn_Vendor_Zend_Locale')) {
             $locale = IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_Zend_Locale');
         }
     }
     if ($locale === null) {
         $locale = new IfwPsn_Vendor_Zend_Locale();
     }
     if (!IfwPsn_Vendor_Zend_Locale::isLocale($locale, true, false)) {
         if (!IfwPsn_Vendor_Zend_Locale::isLocale($locale, false, false)) {
             $locale = IfwPsn_Vendor_Zend_Locale::getLocaleToTerritory($locale);
             if (empty($locale)) {
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Locale_Exception("The locale '{$locale}' is no known locale");
             }
         } else {
             $locale = new IfwPsn_Vendor_Zend_Locale($locale);
         }
     }
     $locale = self::_prepareLocale($locale);
     return $locale;
 }