@@ -79,6 +79,20 @@ The ``Languages`` class provides access to the name of all languages::
79
79
$language = Languages::getName('fr');
80
80
// => 'French'
81
81
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\C omponent\I ntl\L anguages;
86
+
87
+ \L ocale::setDefault('en');
88
+
89
+ $languages = Languages::getAlpha3Names();
90
+ // ('languageCode' => 'languageName')
91
+ // => ['abk' => 'Abkhazian', 'ace' => 'Achinese', ...]
92
+
93
+ $language = Languages::getAlpha3Name('fra');
94
+ // => 'French'
95
+
82
96
All methods accept the translation locale as the last, optional parameter,
83
97
which defaults to the current default locale::
84
98
@@ -94,6 +108,16 @@ to catching the exception, you can also check if a given language code is valid:
94
108
95
109
$isValidLanguage = Languages::exists($languageCode);
96
110
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
+
97
121
.. versionadded :: 4.3
98
122
99
123
The ``Languages `` class was introduced in Symfony 4.3.
@@ -137,34 +161,57 @@ Country Names
137
161
~~~~~~~~~~~~~
138
162
139
163
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::
142
166
143
167
use Symfony\Component\Intl\Countries;
144
168
145
169
\Locale::setDefault('en');
146
170
171
+ // Indexed with alpha-2
147
172
$countries = Countries::getNames();
148
173
// ('countryCode' => 'countryName')
149
174
// => ['AF' => 'Afghanistan', 'AX' => 'Åland Islands', ...]
150
175
176
+ // Indexed with alhpa-3
177
+ $countries = Countries::getAlpha3Names();
178
+ // ('countryCode' => 'countryName')
179
+ // => ['AFG' => 'Afghanistan', 'ALA' => 'Åland Islands', ...]
180
+
151
181
$country = Countries::getName('GB');
152
182
// => 'United Kingdom'
153
183
184
+ $country = Countries::getAlpha3Name('NOR');
185
+ // => 'Norway'
186
+
154
187
All methods accept the translation locale as the last, optional parameter,
155
188
which defaults to the current default locale::
156
189
157
190
$countries = Countries::getNames('de');
158
191
// => ['AF' => 'Afghanistan', 'EG' => 'Ägypten', ...]
159
192
193
+ $countries = Countries::getAlpha3Names('de');
194
+ // => ['AFG' => 'Afghanistan', 'EGY' => 'Ägypten', ...]
195
+
160
196
$country = Countries::getName('GB', 'de');
161
197
// => 'Vereinigtes Königreich'
162
198
199
+ $country = Countries::getName('GBR', 'de');
200
+ // => 'Vereinigtes Königreich'
201
+
163
202
If the given country code doesn't exist, the methods trigger a
164
203
:class: `Symfony\\ Component\\ Intl\\ Exception\\ MissingResourceException `. In addition
165
204
to catching the exception, you can also check if a given country code is valid::
166
205
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);
168
215
169
216
.. versionadded :: 4.3
170
217
@@ -354,5 +401,6 @@ Learn more
354
401
.. _ICU library : http://site.icu-project.org/
355
402
.. _`Unicode ISO 15924 Registry` : https://www.unicode.org/iso15924/iso15924-codes.html
356
403
.. _`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
357
405
.. _`UTC/GMT time offsets` : https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
358
406
.. _`daylight saving time (DST)` : https://en.wikipedia.org/wiki/Daylight_saving_time
0 commit comments