@@ -209,125 +209,152 @@ locale will be merged. In order to suppress this behavior, the last parameter
209
209
Accessing ICU Data
210
210
------------------
211
211
212
- The ICU data is located in several "resource bundles". You can access a PHP
213
- wrapper of these bundles through the static
214
- :class: `Symfony\\ Component\\ Intl\\ Intl ` class. At the moment, the following
215
- data is supported:
212
+ This component provides the following ICU data:
216
213
217
214
* `Language and Script Names `_
218
- * `Country Names `_
215
+ * `Country and Region Names `_
219
216
* `Locales `_
220
217
* `Currencies `_
221
218
222
219
Language and Script Names
223
220
~~~~~~~~~~~~~~~~~~~~~~~~~
224
221
225
- The translations of language and script names can be found in the language
226
- bundle::
222
+ The ``Languages `` class provides access to the name of all languages::
227
223
228
- use Symfony\Component\Intl\Intl ;
224
+ use Symfony\Component\Intl\Languages ;
229
225
230
226
\Locale::setDefault('en');
231
227
232
- $languages = Intl::getLanguageBundle()->getLanguageNames ();
228
+ $languages = Languages::getNames ();
233
229
// => ['ab' => 'Abkhazian', ...]
234
230
235
- $language = Intl::getLanguageBundle()->getLanguageName ('de');
231
+ $language = Languages::getName ('de');
236
232
// => 'German'
237
233
238
- $language = Intl::getLanguageBundle()->getLanguageName ('de', 'AT');
234
+ $language = Languages::getName ('de', 'AT');
239
235
// => 'Austrian German'
240
236
241
- $scripts = Intl::getLanguageBundle()->getScriptNames();
237
+ All methods accept the translation locale as the last, optional parameter,
238
+ which defaults to the current default locale::
239
+
240
+ $languages = Languages::getNames('de');
241
+ // => ['ab' => 'Abchasisch', ...]
242
+
243
+ .. versionadded :: 4.3
244
+
245
+ The ``Languages `` class was introduced in Symfony 4.3.
246
+
247
+ The ``Scripts `` class provides access to the optional four-letter script code
248
+ that can follow the language code according to the `Unicode ISO 15924 Registry `_
249
+ (e.g. ``HANS `` in ``zh_HANS `` for simplified Chinese and ``HANT `` in ``zh_HANT ``
250
+ for traditional Chinese)::
251
+
252
+ use Symfony\Component\Intl\Scripts;
253
+
254
+ \Locale::setDefault('en');
255
+
256
+ $scripts = Scripts::getNames();
242
257
// => ['Arab' => 'Arabic', ...]
243
258
244
- $script = Intl::getLanguageBundle()->getScriptName ('Hans');
259
+ $script = Scripts::getName ('Hans');
245
260
// => 'Simplified'
246
261
247
- All methods accept the translation locale as the last, optional parameter,
248
- which defaults to the current default locale::
262
+ .. versionadded :: 4.3
249
263
250
- $languages = Intl::getLanguageBundle()->getLanguageNames('de');
251
- // => ['ab' => 'Abchasisch', ...]
264
+ The ``Scrcipts `` class was introduced in Symfony 4.3.
265
+
266
+ .. _country-names :
252
267
253
- Country Names
254
- ~~~~~~~~~~~~~
268
+ Country and Region Names
269
+ ~~~~~~~~~~~~~~~~~~~~~~~~
255
270
256
- The translations of country names can be found in the region bundle::
271
+ In the world there are some territorial disputes that make it hard to define
272
+ what a country is. That's why the Intl component provides a ``Regions `` class
273
+ instead of a ``Countries `` class::
257
274
258
- use Symfony\Component\Intl\Intl ;
275
+ use Symfony\Component\Intl\Regions ;
259
276
260
277
\Locale::setDefault('en');
261
278
262
- $countries = Intl::getRegionBundle()->getCountryNames ();
279
+ $countries = Regions::getNames ();
263
280
// => ['AF' => 'Afghanistan', ...]
264
281
265
- $country = Intl::getRegionBundle()->getCountryName ('GB');
282
+ $country = Regions::getName ('GB');
266
283
// => 'United Kingdom'
267
284
268
285
All methods accept the translation locale as the last, optional parameter,
269
286
which defaults to the current default locale::
270
287
271
- $countries = Intl::getRegionBundle()->getCountryNames ('de');
288
+ $countries = Regions::getNames ('de');
272
289
// => ['AF' => 'Afghanistan', ...]
273
290
291
+ .. versionadded :: 4.3
292
+
293
+ The ``Regions `` class was introduced in Symfony 4.3.
294
+
274
295
Locales
275
296
~~~~~~~
276
297
277
- The translations of locale names can be found in the locale bundle::
298
+ A locale is the combination of a language and a region. For example, "Chinese"
299
+ is the language and ``zh_Hans_MO `` is the locale for "Chinese" (language) +
300
+ "Simplified" (script) + "Macau SAR China" (region). The ``Locales `` class
301
+ provides access to the name of all locales::
278
302
279
- use Symfony\Component\Intl\Intl ;
303
+ use Symfony\Component\Intl\Locales ;
280
304
281
305
\Locale::setDefault('en');
282
306
283
- $locales = Intl::getLocaleBundle()->getLocaleNames ();
307
+ $locales = Locales::getNames ();
284
308
// => ['af' => 'Afrikaans', ...]
285
309
286
- $locale = Intl::getLocaleBundle()->getLocaleName ('zh_Hans_MO');
310
+ $locale = Locales::getName ('zh_Hans_MO');
287
311
// => 'Chinese (Simplified, Macau SAR China)'
288
312
289
313
All methods accept the translation locale as the last, optional parameter,
290
314
which defaults to the current default locale::
291
315
292
- $locales = Intl::getLocaleBundle()->getLocaleNames ('de');
316
+ $locales = Locales::getNames ('de');
293
317
// => ['af' => 'Afrikaans', ...]
294
318
319
+ .. versionadded :: 4.3
320
+
321
+ The ``Locales `` class was introduced in Symfony 4.3.
322
+
295
323
Currencies
296
324
~~~~~~~~~~
297
325
298
- The translations of currency names and other currency-related information can
299
- be found in the currency bundle ::
326
+ The `` Currencies `` class provides access to the name of all currencies as well
327
+ as some of their information (symbol, fraction digits, etc.) ::
300
328
301
- use Symfony\Component\Intl\Intl ;
329
+ use Symfony\Component\Intl\Currencies ;
302
330
303
331
\Locale::setDefault('en');
304
332
305
- $currencies = Intl::getCurrencyBundle()->getCurrencyNames ();
333
+ $currencies = Currencies::getNames ();
306
334
// => ['AFN' => 'Afghan Afghani', ...]
307
335
308
- $currency = Intl::getCurrencyBundle()->getCurrencyName ('INR');
336
+ $currency = Currencies::getName ('INR');
309
337
// => 'Indian Rupee'
310
338
311
- $symbol = Intl::getCurrencyBundle()->getCurrencySymbol ('INR');
339
+ $symbol = Currencies::getSymbol ('INR');
312
340
// => '₹'
313
341
314
- $fractionDigits = Intl::getCurrencyBundle()-> getFractionDigits('INR');
342
+ $fractionDigits = Currencies:: getFractionDigits('INR');
315
343
// => 2
316
344
317
- $roundingIncrement = Intl::getCurrencyBundle()-> getRoundingIncrement('INR');
345
+ $roundingIncrement = Currencies:: getRoundingIncrement('INR');
318
346
// => 0
319
347
320
- All methods (except for
321
- :method: `Symfony\\ Component\\ Intl\\ ResourceBundle\\ CurrencyBundleInterface::getFractionDigits `
322
- and
323
- :method: `Symfony\\ Component\\ Intl\\ ResourceBundle\\ CurrencyBundleInterface::getRoundingIncrement `)
324
- accept the translation locale as the last, optional parameter, which defaults
325
- to the current default locale::
348
+ All methods (except for ``getFractionDigits() `` and ``getRoundingIncrement() ``)
349
+ accept the translation locale as the last, optional parameter, which defaults to
350
+ the current default locale::
326
351
327
- $currencies = Intl::getCurrencyBundle()->getCurrencyNames ('de');
352
+ $currencies = Currencies::getNames ('de');
328
353
// => ['AFN' => 'Afghanische Afghani', ...]
329
354
330
- That's all you need to know for now. Have fun coding!
355
+ .. versionadded :: 4.3
356
+
357
+ The ``Currencies `` class was introduced in Symfony 4.3.
331
358
332
359
Learn more
333
360
----------
@@ -346,3 +373,4 @@ Learn more
346
373
.. _intl extension : https://php.net/manual/en/book.intl.php
347
374
.. _install the intl extension : https://php.net/manual/en/intl.setup.php
348
375
.. _ICU library : http://site.icu-project.org/
376
+ .. _`Unicode ISO 15924 Registry` : https://www.unicode.org/iso15924/iso15924-codes.html
0 commit comments