Punic\Territory::getLanguages PHP Метод

getLanguages() публичный статический Метод

Return the list of languages spoken in a territory.
public static getLanguages ( string $territoryCode, string $filterStatuses = '', string $onlyCodes = false ) : array | null
$territoryCode string The territory code
$filterStatuses string Filter language status.
  • If empty no filter will be applied
  • 'o' to include official languages
  • 'r' to include official regional languages
  • 'f' to include de facto official languages
  • 'm' to include official minority languages
  • 'u' to include unofficial or unknown languages
$onlyCodes string Set to true to retrieve only the language codes. If set to false (default) you'll receive a list of arrays with these keys:
  • string id: the language identifier
  • string status: 'o' for official; 'r' for official regional; 'f' for de facto official; 'm' for official minority; 'u' for unofficial or unknown
  • number population: the amount of people speaking the language (%)
  • number|null writing: the amount of people able to write (%). May be null if no data is available
Результат array | null Return the languages spoken in the specified territory, as described by the $onlyCodes parameter (or null if $territoryCode is not valid or no data is available)
    public static function getLanguages($territoryCode, $filterStatuses = '', $onlyCodes = false)
    {
        $result = null;
        $info = self::getTerritoryInfo($territoryCode);
        if (is_array($info)) {
            $result = array();
            foreach ($info['languages'] as $languageID => $languageInfo) {
                if (!isset($languageInfo['status'])) {
                    $languageInfo['status'] = 'u';
                }
                if (strlen($filterStatuses) === 0 || stripos($filterStatuses, $languageInfo['status']) !== false) {
                    if (!isset($languageInfo['writing'])) {
                        $languageInfo['writing'] = null;
                    }
                    if ($onlyCodes) {
                        $result[] = $languageID;
                    } else {
                        $result[] = array_merge(array('id' => $languageID), $languageInfo);
                    }
                }
            }
        }
        return $result;
    }

Usage Example

Пример #1
0
 private function isNativeTranslation($translation)
 {
     if ($translation instanceof RegionTranslation) {
         $country = $translation->region->country->code;
     } elseif ($translation instanceof CountryTranslation) {
         $country = $translation->country->code;
     } else {
         return;
     }
     $locale = str_replace('-', '_', $translation->locale);
     $languages = Territory::getLanguages($country, 'of', true);
     $languages[] = $locale . '_' . $country;
     $translation->is_native = in_array($locale, $languages);
 }
All Usage Examples Of Punic\Territory::getLanguages