Skip to content

Update intl.rst #12175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions components/intl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,47 +77,42 @@ according to the `ISO 639-1 alpha-2`_ list and the `ISO 639-2 alpha-3`_ list::
// ('languageCode' => 'languageName')
// => ['ab' => 'Abkhazian', 'ace' => 'Achinese', ...]

$language = Languages::getName('fr');
// => 'French'

You can also use the ISO 639-2 three-letter language codes instead of
the ISO 639-1 two-letter codes, respectively called alpha3 and alpha2 codes::

use Symfony\Component\Intl\Languages;

\Locale::setDefault('en');

$languages = Languages::getAlpha3Names();
// ('languageCode' => 'languageName')
// => ['abk' => 'Abkhazian', 'ace' => 'Achinese', ...]

$language = Languages::getAlpha3Name('fra');
$language = Languages::getName('fr');
// => 'French'

.. versionadded:: 4.4

The support for alpha3 codes was introduced in Symfony 4.4.
$language = Languages::getAlpha3Name('fra');
// => 'French'

All methods accept the translation locale as the last, optional parameter,
which defaults to the current default locale::

$languages = Languages::getNames('de');
// => ['ab' => 'Abchasisch', 'ace' => 'Aceh', ...]

$languages = Languages::getAlpha3Names('de');
// => ['abk' => 'Abchasisch', 'ace' => 'Aceh', ...]

$language = Languages::getName('fr', 'de');
// => 'Französisch'

$language = Languages::getAlpha3Name('fra', 'de');
// => 'Französisch'

If the given locale doesn't exist, the methods trigger a
:class:`Symfony\\Component\\Intl\\Exception\\MissingResourceException`. In addition
to catching the exception, you can also check if a given language code is valid::

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

Or if you have a three-letter language code you want to check::
Or if you have a alpha3 language code you want to check::

$isValidLanguage = Languages::alpha3CodeExists($alpha3Code);

You may convert codes between two-letter ISO 639-1 (alpha2) and three-letter ISO 639-2 (alpha3) codes::
You may convert codes between two-letter alpha2 and three-letter alpha3 codes::

$alpha3Code = Languages::getAlpha3Code($alpha2Code);

Expand All @@ -127,6 +122,10 @@ You may convert codes between two-letter ISO 639-1 (alpha2) and three-letter ISO

The ``Languages`` class was introduced in Symfony 4.3.

.. versionadded:: 4.4

The full support for alpha3 codes was introduced in Symfony 4.4.

The ``Scripts`` class provides access to the optional four-letter script code
that can follow the language code according to the `Unicode ISO 15924 Registry`_
(e.g. ``HANS`` in ``zh_HANS`` for simplified Chinese and ``HANT`` in ``zh_HANT``
Expand Down Expand Up @@ -187,10 +186,6 @@ of officially recognized countries and territories::
$country = Countries::getAlpha3Name('NOR');
// => 'Norway'

.. versionadded:: 4.4

The support for alpha3 codes was introduced in Symfony 4.4.

All methods accept the translation locale as the last, optional parameter,
which defaults to the current default locale::

Expand Down Expand Up @@ -226,6 +221,10 @@ You may convert codes between two-letter alpha2 and three-letter alpha3 codes::

The ``Countries`` class was introduced in Symfony 4.3.

.. versionadded:: 4.4

The support for alpha3 codes was introduced in Symfony 4.4.

Locales
~~~~~~~

Expand Down