ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Gettext\Languages\CldrData Class Reference

Holds the CLDR data. More...

+ Collaboration diagram for Gettext\Languages\CldrData:

Static Public Member Functions

static getLanguageNames ()
 Returns a dictionary containing the language names. More...
 
static getTerritoryNames ()
 Return a dictionary containing the territory names (in US English). More...
 
static getScriptNames ($standAlone)
 Return a dictionary containing the script names (in US English). More...
 
static getPlurals ()
 
static getSupersededLanguages ()
 Return a list of superseded language codes. More...
 
static getLanguageInfo ($id)
 Retrieve the name of a language, as well as if a language code is deprecated in favor of another language code. More...
 

Data Fields

const OTHER_CATEGORY = 'other'
 

Static Public Attributes

static $categories = array('zero', 'one', 'two', 'few', 'many', self::OTHER_CATEGORY)
 

Static Private Member Functions

static getData ($key)
 Returns the loaded CLDR data. More...
 

Static Private Attributes

static $data
 
static $plurals
 

Detailed Description

Holds the CLDR data.

Definition at line 9 of file CldrData.php.

Member Function Documentation

◆ getData()

static Gettext\Languages\CldrData::getData (   $key)
staticprivate

Returns the loaded CLDR data.

Parameters
string$keyCan be 'languages', 'territories', 'plurals', 'supersededLanguages', 'scripts', 'standAloneScripts'

Definition at line 30 of file CldrData.php.

31 {
32 if (!isset(self::$data)) {
33 $fixKeys = function ($list, &$standAlone = null) {
34 $result = array();
35 $standAlone = array();
36 $match = null;
37 foreach ($list as $key => $value) {
38 $variant = '';
39 if (preg_match('/^(.+)-alt-(short|variant|stand-alone|long)$/', $key, $match)) {
40 $key = $match[1];
41 $variant = $match[2];
42 }
43 $key = str_replace('-', '_', $key);
44 switch ($key) {
45 case 'root': // Language: Root
46 case 'und': // Language: Unknown Language
47 case 'zxx': // Language: No linguistic content
48 case 'ZZ': // Territory: Unknown Region
49 case 'Zinh': // Script: Inherited
50 case 'Zmth': // Script: Mathematical Notation
51 case 'Zsym': // Script: Symbols
52 case 'Zxxx': // Script: Unwritten
53 case 'Zyyy': // Script: Common
54 case 'Zzzz': // Script: Unknown Script
55 break;
56 default:
57 switch ($variant) {
58 case 'stand-alone':
59 $standAlone[$key] = $value;
60 break;
61 case '':
62 $result[$key] = $value;
63 break;
64 }
65 break;
66 }
67 }
68
69 return $result;
70 };
71 $data = array();
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();
83 // Remove the languages for which we don't have plurals
84 $m = null;
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]);
89 }
90 } else {
91 unset($data['languages'][$missingPlural]);
92 }
93 }
94 // Fix the languages for which we have plurals
95 $formerCodes = array(
96 'in' => 'id', // former Indonesian
97 'iw' => 'he', // former Hebrew
98 'ji' => 'yi', // former Yiddish
99 'jw' => 'jv', // former Javanese
100 'mo' => 'ro_MD', // former Moldavian
101 );
102 $knownMissingLanguages = array(
103 'bh' => 'Bihari',
104 'guw' => 'Gun',
105 'nah' => 'Nahuatl',
106 'smi' => 'Sami',
107 );
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];
112 } else {
113 if (isset($knownMissingLanguages[$missingLanguage])) {
114 $data['languages'][$missingLanguage] = $knownMissingLanguages[$missingLanguage];
115 } else {
116 throw new Exception("We have the plural rule for the language '$missingLanguage' but we don't have its language name");
117 }
118 }
119 }
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);
127 }
128 if (!@isset(self::$data[$key])) {
129 throw new Exception("Invalid CLDR data key: '$key'");
130 }
131
132 return self::$data[$key];
133 }
$result
$key
Definition: croninfo.php:18
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
$data
Definition: bench.php:6

References Gettext\Languages\CldrData\$data, $data, $key, $list, $m, and $result.

Referenced by Gettext\Languages\CldrData\getLanguageNames(), Gettext\Languages\CldrData\getPlurals(), Gettext\Languages\CldrData\getScriptNames(), Gettext\Languages\CldrData\getSupersededLanguages(), and Gettext\Languages\CldrData\getTerritoryNames().

+ Here is the caller graph for this function:

◆ getLanguageInfo()

static Gettext\Languages\CldrData::getLanguageInfo (   $id)
static

Retrieve the name of a language, as well as if a language code is deprecated in favor of another language code.

Parameters
string$idThe language identifier.
Returns
array|null Returns an array with the keys 'id' (normalized), 'name', 'supersededBy' (optional), 'territory' (optional), 'script' (optional), 'baseLanguage' (optional), 'categories'. If $id is not valid returns null.

Definition at line 199 of file CldrData.php.

200 {
201 $result = null;
202 $matches = array();
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;
210 }
211 if (isset($territoryId)) {
212 $normalizedId .= '_'.$territoryId;
213 }
214 // Structure precedence: see Likely Subtags - http://www.unicode.org/reports/tr35/tr35-31/tr35.html#Likely_Subtags
215 $variants = array();
216 $variantsWithScript = array();
217 $variantsWithTerritory = array();
218 if (isset($scriptId) && isset($territoryId)) {
219 $variantsWithTerritory[] = $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}_{$territoryId}";
220 }
221 if (isset($scriptId)) {
222 $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}";
223 }
224 if (isset($territoryId)) {
225 $variantsWithTerritory[] = $variants[] = "{$languageId}_{$territoryId}";
226 }
227 $variants[] = $languageId;
228 $allGood = true;
229 $scriptName = null;
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];
237 } else {
238 $allGood = false;
239 }
240 }
241 $territoryName = null;
242 if (isset($territoryId)) {
243 $territoryNames = self::getTerritoryNames();
244 if (isset($territoryNames[$territoryId])) {
245 if ($territoryId !== '001') {
246 $territoryName = $territoryNames[$territoryId];
247 }
248 } else {
249 $allGood = false;
250 }
251 }
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;
259 }
260 if (isset($territoryName) && (!in_array($variant, $variantsWithTerritory))) {
261 $languageName .= ' ('.$territoryNames[$territoryId].')';
262 }
263 break;
264 }
265 }
266 if (!isset($languageName)) {
267 $allGood = false;
268 }
269 $baseLanguage = null;
270 if (isset($scriptId) || isset($territoryId)) {
271 if (isset($languageNames[$languageId]) && ($languageNames[$languageId] !== $languageName)) {
272 $baseLanguage = $languageNames[$languageId];
273 }
274 }
275 $plural = null;
277 foreach ($variants as $variant) {
278 if (isset($plurals[$variant])) {
279 $plural = $plurals[$variant];
280 break;
281 }
282 }
283 if (!isset($plural)) {
284 $allGood = false;
285 }
286 $supersededBy = null;
287 $supersededBys = self::getSupersededLanguages();
288 foreach ($variants as $variant) {
289 if (isset($supersededBys[$variant])) {
290 $supersededBy = $supersededBys[$variant];
291 break;
292 }
293 }
294 if ($allGood) {
295 $result = array();
296 $result['id'] = $normalizedId;
297 $result['name'] = $languageName;
298 if (isset($supersededBy)) {
299 $result['supersededBy'] = $supersededBy;
300 }
301 if (isset($scriptStandAloneName)) {
302 $result['script'] = $scriptStandAloneName;
303 }
304 if (isset($territoryName)) {
305 $result['territory'] = $territoryName;
306 }
307 if (isset($baseLanguage)) {
308 $result['baseLanguage'] = $baseLanguage;
309 }
310 $result['categories'] = $plural;
311 }
312 }
313
314 return $result;
315 }
static getLanguageNames()
Returns a dictionary containing the language names.
Definition: CldrData.php:140
static getScriptNames($standAlone)
Return a dictionary containing the script names (in US English).
Definition: CldrData.php:161
static getTerritoryNames()
Return a dictionary containing the territory names (in US English).
Definition: CldrData.php:150
static getSupersededLanguages()
Return a list of superseded language codes.
Definition: CldrData.php:190
if(!array_key_exists('StateId', $_REQUEST)) $id

References $id, Gettext\Languages\CldrData\$plurals, $result, Gettext\Languages\CldrData\getLanguageNames(), Gettext\Languages\CldrData\getPlurals(), Gettext\Languages\CldrData\getScriptNames(), Gettext\Languages\CldrData\getSupersededLanguages(), and Gettext\Languages\CldrData\getTerritoryNames().

Referenced by Gettext\Languages\Language\getAll(), and Gettext\Languages\Language\getById().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLanguageNames()

static Gettext\Languages\CldrData::getLanguageNames ( )
static

Returns a dictionary containing the language names.

The keys are the language identifiers. The values are the language names in US English.

Returns
string[]

Definition at line 140 of file CldrData.php.

141 {
142 return self::getData('languages');
143 }
static getData($key)
Returns the loaded CLDR data.
Definition: CldrData.php:30

References Gettext\Languages\CldrData\getData().

Referenced by Gettext\Languages\Language\getAll(), and Gettext\Languages\CldrData\getLanguageInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPlurals()

static Gettext\Languages\CldrData::getPlurals ( )
static

Definition at line 182 of file CldrData.php.

183 {
184 return self::getData('plurals');
185 }

References Gettext\Languages\CldrData\getData().

Referenced by Gettext\Languages\CldrData\getLanguageInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getScriptNames()

static Gettext\Languages\CldrData::getScriptNames (   $standAlone)
static

Return a dictionary containing the script names (in US English).

The keys are the script identifiers. The values are the script names in US English.

Parameters
bool$standAloneSet to true to retrieve the stand-alone script names, false otherwise.
Returns
string[]

Definition at line 161 of file CldrData.php.

162 {
163 return self::getData($standAlone ? 'standAloneScripts' : 'scripts');
164 }

References Gettext\Languages\CldrData\getData().

Referenced by Gettext\Languages\CldrData\getLanguageInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSupersededLanguages()

static Gettext\Languages\CldrData::getSupersededLanguages ( )
static

Return a list of superseded language codes.

Returns
array Keys are the former language codes, values are the new language/locale codes.

Definition at line 190 of file CldrData.php.

191 {
192 return self::getData('supersededLanguages');
193 }

References Gettext\Languages\CldrData\getData().

Referenced by Gettext\Languages\CldrData\getLanguageInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTerritoryNames()

static Gettext\Languages\CldrData::getTerritoryNames ( )
static

Return a dictionary containing the territory names (in US English).

The keys are the territory identifiers. The values are the territory names in US English.

Returns
string[]

Definition at line 150 of file CldrData.php.

151 {
152 return self::getData('territories');
153 }

References Gettext\Languages\CldrData\getData().

Referenced by Gettext\Languages\CldrData\getLanguageInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $categories

Gettext\Languages\CldrData::$categories = array('zero', 'one', 'two', 'few', 'many', self::OTHER_CATEGORY)
static

◆ $data

Gettext\Languages\CldrData::$data
staticprivate

Definition at line 25 of file CldrData.php.

Referenced by Gettext\Languages\CldrData\getData().

◆ $plurals

Gettext\Languages\CldrData::$plurals
staticprivate

Definition at line 168 of file CldrData.php.

Referenced by Gettext\Languages\CldrData\getLanguageInfo().

◆ OTHER_CATEGORY


The documentation for this class was generated from the following file: