20 public static $categories = array(
'zero',
'one',
'two',
'few',
'many', self::OTHER_CATEGORY);
33 $fixKeys =
function (
$list, &$standAlone = null) {
35 $standAlone = array();
39 if (preg_match(
'/^(.+)-alt-(short|variant|stand-alone|long)$/',
$key, $match)) {
59 $standAlone[
$key] = $value;
72 $json = json_decode(file_get_contents(__DIR__.
'/cldr-data/main/en-US/languages.json'),
true);
73 $data[
'languages'] = $fixKeys($json[
'main'][
'en-US'][
'localeDisplayNames'][
'languages']);
74 $json = json_decode(file_get_contents(__DIR__.
'/cldr-data/main/en-US/territories.json'),
true);
75 $data[
'territories'] = $fixKeys($json[
'main'][
'en-US'][
'localeDisplayNames'][
'territories']);
76 $json = json_decode(file_get_contents(__DIR__.
'/cldr-data/supplemental/plurals.json'),
true);
77 $data[
'plurals'] = $fixKeys($json[
'supplemental'][
'plurals-type-cardinal']);
78 $json = json_decode(file_get_contents(__DIR__.
'/cldr-data/main/en-US/scripts.json'),
true);
79 $data[
'scripts'] = $fixKeys($json[
'main'][
'en-US'][
'localeDisplayNames'][
'scripts'],
$data[
'standAloneScripts']);
80 $data[
'standAloneScripts'] = array_merge(
$data[
'scripts'],
$data[
'standAloneScripts']);
81 $data[
'scripts'] = array_merge(
$data[
'standAloneScripts'],
$data[
'scripts']);
82 $data[
'supersededLanguages'] = array();
85 foreach (array_keys(array_diff_key(
$data[
'languages'],
$data[
'plurals'])) as $missingPlural) {
86 if (preg_match(
'/^([a-z]{2,3})_/', $missingPlural,
$m)) {
87 if (!isset(
$data[
'plurals'][
$m[1]])) {
88 unset(
$data[
'languages'][$missingPlural]);
91 unset(
$data[
'languages'][$missingPlural]);
102 $knownMissingLanguages = array(
108 foreach (array_keys(array_diff_key(
$data[
'plurals'],
$data[
'languages'])) as $missingLanguage) {
109 if (isset($formerCodes[$missingLanguage]) && isset(
$data[
'languages'][$formerCodes[$missingLanguage]])) {
110 $data[
'languages'][$missingLanguage] =
$data[
'languages'][$formerCodes[$missingLanguage]];
111 $data[
'supersededLanguages'][$missingLanguage] = $formerCodes[$missingLanguage];
113 if (isset($knownMissingLanguages[$missingLanguage])) {
114 $data[
'languages'][$missingLanguage] = $knownMissingLanguages[$missingLanguage];
116 throw new Exception(
"We have the plural rule for the language '$missingLanguage' but we don't have its language name");
120 ksort(
$data[
'languages'], SORT_STRING);
121 ksort(
$data[
'territories'], SORT_STRING);
122 ksort(
$data[
'plurals'], SORT_STRING);
123 ksort(
$data[
'scripts'], SORT_STRING);
124 ksort(
$data[
'standAloneScripts'], SORT_STRING);
125 ksort(
$data[
'supersededLanguages'], SORT_STRING);
129 throw new Exception(
"Invalid CLDR data key: '$key'");
142 return self::getData(
'languages');
152 return self::getData(
'territories');
163 return self::getData($standAlone ?
'standAloneScripts' :
'scripts');
184 return self::getData(
'plurals');
192 return self::getData(
'supersededLanguages');
203 if (preg_match(
'/^([a-z]{2,3})(?:[_\-]([a-z]{4}))?(?:[_\-]([a-z]{2}|[0-9]{3}))?(?:$|-)/i',
$id, $matches)) {
204 $languageId = strtolower($matches[1]);
205 $scriptId = (isset($matches[2]) && ($matches[2] !==
'')) ? ucfirst(strtolower($matches[2])) : null;
206 $territoryId = (isset($matches[3]) && ($matches[3] !==
'')) ? strtoupper($matches[3]) : null;
207 $normalizedId = $languageId;
208 if (isset($scriptId)) {
209 $normalizedId .=
'_'.$scriptId;
211 if (isset($territoryId)) {
212 $normalizedId .=
'_'.$territoryId;
216 $variantsWithScript = array();
217 $variantsWithTerritory = array();
218 if (isset($scriptId) && isset($territoryId)) {
219 $variantsWithTerritory[] = $variantsWithScript[] = $variants[] =
"{$languageId}_{$scriptId}_{$territoryId}";
221 if (isset($scriptId)) {
222 $variantsWithScript[] = $variants[] =
"{$languageId}_{$scriptId}";
224 if (isset($territoryId)) {
225 $variantsWithTerritory[] = $variants[] =
"{$languageId}_{$territoryId}";
227 $variants[] = $languageId;
230 $scriptStandAloneName = null;
231 if (isset($scriptId)) {
232 $scriptNames = self::getScriptNames(
false);
233 if (isset($scriptNames[$scriptId])) {
234 $scriptName = $scriptNames[$scriptId];
235 $scriptStandAloneNames = self::getScriptNames(
true);
236 $scriptStandAloneName = $scriptStandAloneNames[$scriptId];
241 $territoryName = null;
242 if (isset($territoryId)) {
243 $territoryNames = self::getTerritoryNames();
244 if (isset($territoryNames[$territoryId])) {
245 if ($territoryId !==
'001') {
246 $territoryName = $territoryNames[$territoryId];
252 $languageName = null;
253 $languageNames = self::getLanguageNames();
254 foreach ($variants as $variant) {
255 if (isset($languageNames[$variant])) {
256 $languageName = $languageNames[$variant];
257 if (isset($scriptName) && (!in_array($variant, $variantsWithScript))) {
258 $languageName = $scriptName.
' '.$languageName;
260 if (isset($territoryName) && (!in_array($variant, $variantsWithTerritory))) {
261 $languageName .=
' ('.$territoryNames[$territoryId].
')';
266 if (!isset($languageName)) {
269 $baseLanguage = null;
270 if (isset($scriptId) || isset($territoryId)) {
271 if (isset($languageNames[$languageId]) && ($languageNames[$languageId] !== $languageName)) {
272 $baseLanguage = $languageNames[$languageId];
277 foreach ($variants as $variant) {
283 if (!isset($plural)) {
286 $supersededBy = null;
287 $supersededBys = self::getSupersededLanguages();
288 foreach ($variants as $variant) {
289 if (isset($supersededBys[$variant])) {
290 $supersededBy = $supersededBys[$variant];
297 $result[
'name'] = $languageName;
298 if (isset($supersededBy)) {
299 $result[
'supersededBy'] = $supersededBy;
301 if (isset($scriptStandAloneName)) {
302 $result[
'script'] = $scriptStandAloneName;
304 if (isset($territoryName)) {
305 $result[
'territory'] = $territoryName;
307 if (isset($baseLanguage)) {
308 $result[
'baseLanguage'] = $baseLanguage;
310 $result[
'categories'] = $plural;
if(isset($_REQUEST['delete'])) $list
if(!array_key_exists('StateId', $_REQUEST)) $id
static getData($key)
Returns the loaded CLDR data.
static getLanguageNames()
Returns a dictionary containing the language names.
static getLanguageInfo($id)
Retrieve the name of a language, as well as if a language code is deprecated in favor of another lang...
static getTerritoryNames()
Return a dictionary containing the territory names (in US English).
static getScriptNames($standAlone)
Return a dictionary containing the script names (in US English).
static getSupersededLanguages()
Return a list of superseded language codes.