示例#1
0
文件: Data.php 项目: ngreimel/kovent
 /**
  * Returns a list of locale identifiers associated to a locale.
  *
  * @param string $locale The locale for which you want the alternatives
  * @param string $addFallback Set to true to add the fallback locale to the result, false otherwise
  *
  * @return array
  */
 protected static function getLocaleAlternatives($locale, $addFallback = true)
 {
     $result = array();
     $localeInfo = static::explodeLocale($locale);
     if (!is_array($localeInfo)) {
         throw new Exception\InvalidLocale($locale);
     }
     $language = $localeInfo['language'];
     $script = $localeInfo['script'];
     $territory = $localeInfo['territory'];
     $parentLocale = $localeInfo['parentLocale'];
     if (!isset($territory[0])) {
         $fullLocale = static::guessFullLocale($language, $script);
         if (isset($fullLocale[0])) {
             $localeInfo = static::explodeLocale($fullLocale);
             $language = $localeInfo['language'];
             $script = $localeInfo['script'];
             $territory = $localeInfo['territory'];
             $parentLocale = $localeInfo['parentLocale'];
         }
     }
     $territories = array();
     while (isset($territory[0])) {
         $territories[] = $territory;
         $territory = Territory::getParentTerritoryCode($territory);
     }
     if (isset($script[0])) {
         foreach ($territories as $territory) {
             $result[] = "{$language}-{$script}-{$territory}";
         }
     }
     if (isset($script[0])) {
         $result[] = "{$language}-{$script}";
     }
     foreach ($territories as $territory) {
         $result[] = "{$language}-{$territory}";
         if ("{$language}-{$territory}" === 'en-US') {
             $result[] = 'root';
         }
     }
     if (isset($parentLocale[0])) {
         $result = array_merge($result, static::getLocaleAlternatives($parentLocale, false));
     }
     $result[] = $language;
     if ($addFallback && $locale !== static::$fallbackLocale) {
         $result = array_merge($result, static::getLocaleAlternatives(static::$fallbackLocale, false));
     }
     for ($i = count($result) - 1; $i > 1; $i--) {
         for ($j = 0; $j < $i; $j++) {
             if ($result[$i] === $result[$j]) {
                 array_splice($result, $i, 1);
                 break;
             }
         }
     }
     $i = array_search('root', $result, true);
     if ($i !== false) {
         array_splice($result, $i, 1);
         $result[] = 'root';
     }
     return $result;
 }
示例#2
0
文件: Unit.php 项目: ngreimel/kovent
 /**
  * Retrieve the standard paper size for a specific territory.
  *
  * @param string $territoryCode The territory code (eg. 'US' for 'United States of America').
  *
  * @return string Return the standard paper size (eg: 'A4' or 'US-Letter') for the specified territory. If $territoryCode is not valid we'll return an empty string.
  */
 public static function getPaperSizeFor($territoryCode)
 {
     $result = '';
     if (is_string($territoryCode) && preg_match('/^[a-z0-9]{2,3}$/i', $territoryCode)) {
         $territoryCode = strtoupper($territoryCode);
         $data = Data::getGeneric('measurementData');
         while (isset($territoryCode[0])) {
             if (isset($data['paperSize'][$territoryCode])) {
                 $result = $data['paperSize'][$territoryCode];
                 break;
             }
             $territoryCode = Territory::getParentTerritoryCode($territoryCode);
         }
     }
     return $result;
 }