Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9130c6a

Browse filesBrowse files
committed
bug #33140 [Intl] Full alpha3 language support (ro0NL)
This PR was merged into the 4.4 branch. Discussion ---------- [Intl] Full alpha3 language support | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #33136 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> I'll validate some more cases with tests. Commits ------- 29aee2d [Intl] Full alpha3 language support
2 parents 98e8681 + 29aee2d commit 9130c6a
Copy full SHA for 9130c6a

File tree

Expand file treeCollapse file tree

5 files changed

+1503
-32
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+1503
-32
lines changed

‎src/Symfony/Component/Intl/Data/Generator/LanguageDataGenerator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Data/Generator/LanguageDataGenerator.php
+36-6Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,12 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, $temp
162162

163163
sort($this->languageCodes);
164164

165-
$alpha2ToAlpha3 = $this->generateAlpha2ToAlpha3Mapping($metadataBundle);
166-
$alpha3ToAlpha2 = array_flip($alpha2ToAlpha3);
167-
asort($alpha3ToAlpha2);
168-
169165
return [
170166
'Version' => $rootBundle['Version'],
171167
'Languages' => $this->languageCodes,
172-
'Alpha2ToAlpha3' => $alpha2ToAlpha3,
173-
'Alpha3ToAlpha2' => $alpha3ToAlpha2,
168+
'Alpha3Languages' => $this->generateAlpha3Codes($this->languageCodes, $metadataBundle),
169+
'Alpha2ToAlpha3' => $this->generateAlpha2ToAlpha3Mapping($metadataBundle),
170+
'Alpha3ToAlpha2' => $this->generateAlpha3ToAlpha2Mapping($metadataBundle),
174171
];
175172
}
176173

@@ -179,6 +176,23 @@ private static function generateLanguageNames(ArrayAccessibleResourceBundle $loc
179176
return array_diff_key(iterator_to_array($localeBundle['Languages']), self::$blacklist);
180177
}
181178

179+
private function generateAlpha3Codes(array $languageCodes, ArrayAccessibleResourceBundle $metadataBundle): array
180+
{
181+
$alpha3Codes = array_flip(array_filter($languageCodes, static function (string $language): bool {
182+
return 3 === \strlen($language);
183+
}));
184+
185+
foreach ($metadataBundle['alias']['language'] as $alias => $data) {
186+
if (3 === \strlen($alias) && 'overlong' === $data['reason']) {
187+
$alpha3Codes[$alias] = true;
188+
}
189+
}
190+
191+
ksort($alpha3Codes);
192+
193+
return array_keys($alpha3Codes);
194+
}
195+
182196
private function generateAlpha2ToAlpha3Mapping(ArrayAccessibleResourceBundle $metadataBundle)
183197
{
184198
$aliases = iterator_to_array($metadataBundle['alias']['language']);
@@ -213,4 +227,20 @@ private function generateAlpha2ToAlpha3Mapping(ArrayAccessibleResourceBundle $me
213227

214228
return $alpha2ToAlpha3;
215229
}
230+
231+
private function generateAlpha3ToAlpha2Mapping(ArrayAccessibleResourceBundle $metadataBundle): array
232+
{
233+
$alpha3ToAlpha2 = [];
234+
235+
foreach ($metadataBundle['alias']['language'] as $alias => $data) {
236+
$language = $data['replacement'];
237+
if (2 === \strlen($language) && 3 === \strlen($alias) && 'overlong' === $data['reason']) {
238+
$alpha3ToAlpha2[$alias] = $language;
239+
}
240+
}
241+
242+
asort($alpha3ToAlpha2);
243+
244+
return $alpha3ToAlpha2;
245+
}
216246
}

‎src/Symfony/Component/Intl/Languages.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Languages.php
+20-3Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function getAlpha2Code(string $language): string
9898
*/
9999
public static function getAlpha3Codes(): array
100100
{
101-
return self::readEntry(['Alpha2ToAlpha3'], 'meta');
101+
return self::readEntry(['Alpha3Languages'], 'meta');
102102
}
103103

104104
/**
@@ -111,7 +111,12 @@ public static function alpha3CodeExists(string $language): bool
111111

112112
return true;
113113
} catch (MissingResourceException $e) {
114-
return false;
114+
static $cache;
115+
if (null === $cache) {
116+
$cache = array_flip(self::getAlpha3Codes());
117+
}
118+
119+
return isset($cache[$language]);
115120
}
116121
}
117122

@@ -122,7 +127,15 @@ public static function alpha3CodeExists(string $language): bool
122127
*/
123128
public static function getAlpha3Name(string $language, string $displayLocale = null): string
124129
{
125-
return self::getName(self::getAlpha2Code($language), $displayLocale);
130+
try {
131+
return self::getName(self::getAlpha2Code($language), $displayLocale);
132+
} catch (MissingResourceException $e) {
133+
if (3 === \strlen($language)) {
134+
return self::getName($language, $displayLocale);
135+
}
136+
137+
throw $e;
138+
}
126139
}
127140

128141
/**
@@ -137,6 +150,10 @@ public static function getAlpha3Names($displayLocale = null): array
137150
$alpha2Names = self::getNames($displayLocale);
138151
$alpha3Names = [];
139152
foreach ($alpha2Names as $alpha2Code => $name) {
153+
if (3 === \strlen($alpha2Code)) {
154+
$alpha3Names[$alpha2Code] = $name;
155+
continue;
156+
}
140157
try {
141158
$alpha3Names[self::getAlpha3Code($alpha2Code)] = $name;
142159
} catch (MissingResourceException $e) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.