function get_data($index, $dataDir, $locale = 'en', $constraint = null) { $data = array(); $bundle = load_resource_bundle($locale, $dataDir); foreach ($bundle->get($index) as $code => $name) { if (null !== $constraint) { if ($constraint($code)) { $data[$code] = $name; } continue; } $data[$code] = $name; } $collator = new \Collator($locale); $collator->asort($data); return $data; }
// Discover the list of locales for which individual language/region names // exist. This list contains for example "de" and "de_CH", but not "de_DE" which // is equal to "de" $translatedLocales = array_unique(array_merge(list_files($langDir, '.res'), list_files($regionDir, '.res'))); sort($translatedLocales); // For each translated locale, generate a list of locale names // Each locale name has the form: "Language (Script, Region, Variant1, ...) // Script, Region and Variants are optional. If none of them is available, // the braces are not printed. foreach ($translatedLocales as $translatedLocale) { // Don't include ICU's root resource bundle if ($translatedLocale === 'root') { continue; } $langBundle = load_resource_bundle($translatedLocale, $langDir); $regionBundle = load_resource_bundle($translatedLocale, $regionDir); $localeNames = array(); foreach ($supportedLocales as $supportedLocale) { // Don't include ICU's root resource bundle if ($supportedLocale === 'root') { continue; } $lang = \Locale::getPrimaryLanguage($supportedLocale); $script = \Locale::getScript($supportedLocale); $region = \Locale::getRegion($supportedLocale); $variants = \Locale::getAllVariants($supportedLocale); // Currently the only available variant is POSIX, which we don't want // to include in the list if (count($variants) > 0) { continue; }