8000 feature #12105 Add documentation about alpha3 methods (terjebraten-ce… · symfony/symfony-docs@31425d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 31425d7

Browse files
committed
feature #12105 Add documentation about alpha3 methods (terjebraten-certua)
This PR was merged into the 4.4 branch. Discussion ---------- Add documentation about alpha3 methods Replaces #12104 Commits ------- 5044b35 Add documentation about alpha3 methods
2 parents a97d940 + 5044b35 commit 31425d7

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

components/intl.rst

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ The ``Languages`` class provides access to the name of all languages::
7979
$language = Languages::getName('fr');
8080
// => 'French'
8181

82+
If you want to you can also use the ISO 639-2 three-letter language codes instead of
83+
the ISO 639-1 two-letter codes. (They are here called alpha3 codes.)
84+
85+
use Symfony\Component\Intl\Languages;
86+
87+
\Locale::setDefault('en');
88+
89+
$languages = Languages::getAlpha3Names();
90+
// ('languageCode' => 'languageName')
91+
// => ['abk' => 'Abkhazian', 'ace' => 'Achinese', ...]
92+
93+
$language = Languages::getAlpha3Name('fra');
94+
// => 'French'
95+
8296
All methods accept the translation locale as the last, optional parameter,
8397
which defaults to the current default locale::
8498

@@ -94,6 +108,16 @@ to catching the exception, you can also check if a given language code is valid:
94108

95109
$isValidLanguage = Languages::exists($languageCode);
96110

111+
Or if you have a three-letter language code you want to check:
112+
113+
$isValidLanguage = Languages::alpha3CodeExists($alpha3Code);
114+
115+
You may convert codes between two-letter ISO 639-1 (alpha2) and three-letter ISO 639-2 (alpha3) codes:
116+
117+
$alpha3Code = Languages::getAlpha3Code($alpha2Code);
118+
119+
$alpha2Code = Languages::getAlpha2Code($alpha3Code);
120+
97121
.. versionadded:: 4.3
98122

99123
The ``Languages`` class was introduced in Symfony 4.3.
@@ -137,34 +161,57 @@ Country Names
137161
~~~~~~~~~~~~~
138162

139163
The ``Countries`` class provides access to the name of all countries according
140-
to the `ISO 3166-1 alpha-2`_ list of officially recognized countries and
141-
territories::
164+
to the `ISO 3166-1 alpha-2`_ list and the `ISO 3166-1 alpha-3`_ list
165+
of officially recognized countries and territories::
142166

143167
use Symfony\Component\Intl\Countries;
144168

145169
\Locale::setDefault('en');
146170

171+
// Indexed with alpha-2
147172
$countries = Countries::getNames();
148173
// ('countryCode' => 'countryName')
149174
// => ['AF' => 'Afghanistan', 'AX' => 'Åland Islands', ...]
150175

176+
// Indexed with alhpa-3
177+
$countries = Countries::getAlpha3Names();
178+
// ('countryCode' => 'countryName')
179+
// => ['AFG' => 'Afghanistan', 'ALA' => 'Åland Islands', ...]
180+
151181
$country = Countries::getName('GB');
152182
// => 'United Kingdom'
153183

184+
$country = Countries::getAlpha3Name('NOR');
185+
// => 'Norway'
186+
154187
All methods accept the translation locale as the last, optional parameter,
155188
which defaults to the current default locale::
156189

157190
$countries = Countries::getNames('de');
158191
// => ['AF' => 'Afghanistan', 'EG' => 'Ägypten', ...]
159192

193+
$countries = Countries::getAlpha3Names('de');
194+
// => ['AFG' => 'Afghanistan', 'EGY' => 'Ägypten', ...]
195+
160196
$country = Countries::getName('GB', 'de');
161197
// => 'Vereinigtes Königreich'
162198

199+
$country = Countries::getName('GBR', 'de');
200+
// => 'Vereinigtes Königreich'
201+
163202
If the given country code doesn't exist, the methods trigger a
164203
:class:`Symfony\\Component\\Intl\\Exception\\MissingResourceException`. In addition
165204
to catching the exception, you can also check if a given country code is valid::
166205

167-
$isValidCountry = Countries::exists($countryCode);
206+
$isValidCountry = Countries::exists($alpha2Code);
207+
208+
$isValidCountry = Countries::alpha3CodeExists($alpha2Code);
209+
210+
You may convert codes between two-letter alpha2 and three-letter alpha3 codes:
211+
212+
$alpha3Code = Countries::getAlpha3Code($alpha2Code);
213+
214+
$alpha2Code = Countries::getAlpha2Code($alpha3Code);
168215

169216
.. versionadded:: 4.3
170217

@@ -354,5 +401,6 @@ Learn more
354401
.. _ICU library: http://site.icu-project.org/
355402
.. _`Unicode ISO 15924 Registry`: https://www.unicode.org/iso15924/iso15924-codes.html
356403
.. _`ISO 3166-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
404+
.. _`ISO 3166-1 alpha-3`: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
357405
.. _`UTC/GMT time offsets`: https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
358406
.. _`daylight saving time (DST)`: https://en.wikipedia.org/wiki/Daylight_saving_time

0 commit comments

Comments
 (0)
0