@@ -79,6 +79,24 @@ The ``Languages`` class provides access to the name of all languages::
79
79
$language = Languages::getName('fr');
80
80
// => 'French'
81
81
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
+
82
100
All methods accept the translation locale as the last, optional parameter,
83
101
which defaults to the current default locale::
84
102
@@ -94,6 +112,16 @@ to catching the exception, you can also check if a given language code is valid:
94
112
95
113
$isValidLanguage = Languages::exists($languageCode);
96
114
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
+
97
125
The ``Scripts `` class provides access to the optional four-letter script code
98
126
that can follow the language code according to the `Unicode ISO 15924 Registry `_
99
127
(e.g. ``HANS `` in ``zh_HANS `` for simplified Chinese and ``HANT `` in ``zh_HANT ``
@@ -129,34 +157,59 @@ Country Names
129
157
~~~~~~~~~~~~~
130
158
131
159
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::
134
162
135
163
use Symfony\Component\Intl\Countries;
136
164
137
165
\Locale::setDefault('en');
138
166
167
+ // Indexed with alpha-2
139
168
$countries = Countries::getNames();
140
- // ('countryCode ' => 'countryName')
169
+ // ('alpha2Code ' => 'countryName')
141
170
// => ['AF' => 'Afghanistan', 'AX' => 'Åland Islands', ...]
142
171
172
+ // Indexed with alhpa-3
173
+ $countries = Countries::getAlpha3Names();
174
+ // ('alpha3Code' => 'countryName')
175
+ // => ['AFG' => 'Afghanistan', 'ALA' => 'Åland Islands', ...]
176
+
143
177
$country = Countries::getName('GB');
144
178
// => 'United Kingdom'
145
179
180
+ $country = Countries::getAlpha3Name('NOR');
181
+ // => 'Norway'
182
+
146
183
All methods accept the translation locale as the last, optional parameter,
147
184
which defaults to the current default locale::
148
185
149
186
$countries = Countries::getNames('de');
150
187
// => ['AF' => 'Afghanistan', 'EG' => 'Ägypten', ...]
151
188
189
+ $countries = Countries::getAlpha3Names('de');
190
+ // => ['AFG' => 'Afghanistan', 'EGY' => 'Ägypten', ...]
191
+
152
192
$country = Countries::getName('GB', 'de');
153
193
// => 'Vereinigtes Königreich'
154
194
195
+ $country = Countries::getAlpha3Name('GBR', 'de');
196
+ // => 'Vereinigtes Königreich'
197
+
155
198
If the given country code doesn't exist, the methods trigger a
156
199
:class: `Symfony\\ Component\\ Intl\\ Exception\\ MissingResourceException `. In addition
157
200
to catching the exception, you can also check if a given country code is valid::
158
201
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);
160
213
161
214
Locales
162
215
~~~~~~~
@@ -330,5 +383,6 @@ Learn more
330
383
.. _ICU library : http://site.icu-project.org/
331
384
.. _`Unicode ISO 15924 Registry` : https://www.unicode.org/iso15924/iso15924-codes.html
332
385
.. _`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
333
387
.. _`UTC/GMT time offsets` : https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
334
388
.. _`daylight saving time (DST)` : https://en.wikipedia.org/wiki/Daylight_saving_time
0 commit comments