8000 Merge branch '4.4' · symfony/symfony-docs@48db983 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48db983

Browse files
committed
Merge branch '4.4'
* 4.4: Tweaks. refs #12105 Add documentation about alpha3 methods
2 parents 5bf67b8 + b3d776d commit 48db983

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

components/intl.rst

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

82+
You can also use the ISO 639-2 three-letter language codes instead of
83+
the ISO 639-1 two-letter codes, respectively called alpha3 and alpha2 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+
96+
.. versionadded:: 4.4
97+
98+
The support for alpha3 codes was introduced in Symfony 4.4.
99+
82100
All methods accept the translation locale as the last, optional parameter,
83101
which defaults to the current default locale::
84102

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

95113
$isValidLanguage = Languages::exists($languageCode);
96114

115+
Or if you have a three-letter language code you want to check::
116+
117+
$isValidLanguage = Languages::alpha3CodeExists($alpha3Code);
118+
119+
You may convert codes between two-letter ISO 639-1 (alpha2) and three-letter ISO 639-2 (alpha3) codes::
120+
121+
$alpha3Code = Languages::getAlpha3Code($alpha2Code);
122+
123+
$alpha2Code = Languages::getAlpha2Code($alpha3Code);
124+
97125
The ``Scripts`` class provides access to the optional four-letter script code
98126
that can follow the language code according to the `Unicode ISO 15924 Registry`_
99127
(e.g. ``HANS`` in ``zh_HANS`` for simplified Chinese and ``HANT`` in ``zh_HANT``
@@ -129,34 +157,59 @@ Country Names
129157
~~~~~~~~~~~~~
130158

131159
The ``Countries`` class provides access to the name of all countries according
132-
to the `ISO 3166-1 alpha-2`_ list of officially recognized countries and
133-
territories::
160+
to the `ISO 3166-1 alpha-2`_ list and the `ISO 3166-1 alpha-3`_ list
161+
of officially recognized countries and territories::
134162

135163
use Symfony\Component\Intl\Countries;
136164

137165
\Locale::setDefault('en');
138166

167+
// Indexed with alpha-2
139168
$countries = Countries::getNames();
140-
// ('countryCode' => 'countryName')
169+
// ('alpha2Code' => 'countryName')
141170
// => ['AF' => 'Afghanistan', 'AX' => 'Åland Islands', ...]
142171

172+
// Indexed with alhpa-3
173+
$countries = Countries::getAlpha3Names();
174+
// ('alpha3Code' => 'countryName')
175+
// => ['AFG' => 'Afghanistan', 'ALA' => 'Åland Islands', ...]
176+
143177
$country = Countries::getName('GB');
144178
// => 'United Kingdom'
145179

180+
$country = Countries::getAlpha3Name('NOR');
181+
// => 'Norway'
182+
146183
All methods accept the translation locale as the last, optional parameter,
147184
which defaults to the current default locale::
148185

149186
$countries = Countries::getNames('de');
150187
// => ['AF' => 'Afghanistan', 'EG' => 'Ägypten', ...]
151188

189+
$countries = Countries::getAlpha3Names('de');
190+
// => ['AFG' => 'Afghanistan', 'EGY' => 'Ägypten', ...]
191+
152192
$country = Countries::getName('GB', 'de');
153193
// => 'Vereinigtes Königreich'
154194

195+
$country = Countries::getAlpha3Name('GBR', 'de');
196+
// => 'Vereinigtes Königreich'
197+
155198
If the given country code doesn't exist, the methods trigger a
156199
:class:`Symfony\\Component\\Intl\\Exception\\MissingResourceException`. In addition
157200
to catching the exception, you can also check if a given country code is valid::
158201

159-
$isValidCountry = Countries::exists($countryCode);
202+
$isValidCountry = Countries::exists($alpha2Code);
203+
204+
Or if you have a alpha3 country code you want to check:
205+
206+
$isValidCountry = Countries::alpha3CodeExists($alpha3Code);
207+
208+
You may convert codes between two-letter alpha2 and three-letter alpha3 codes::
209+
210+
$alpha3Code = Countries::getAlpha3Code($alpha2Code);
211+
212+
$alpha2Code = Countries::getAlpha2Code($alpha3Code);
160213

161214
Locales
162215
~~~~~~~
@@ -330,5 +383,6 @@ Learn more
330383
.. _ICU library: http://site.icu-project.org/
331384
.. _`Unicode ISO 15924 Registry`: https://www.unicode.org/iso15924/iso15924-codes.html
332385
.. _`ISO 3166-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
386+
.. _`ISO 3166-1 alpha-3`: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
333387
.. _`UTC/GMT time offsets`: https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
334388
.. _`daylight saving time (DST)`: https://en.wikipedia.org/wiki/Daylight_saving_time

0 commit comments

Comments
 (0)
0