-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add documentation about alpha3 methods #12105
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,20 @@ The ``Languages`` class provides access to the name of all languages:: | |
$language = Languages::getName('fr'); | ||
// => 'French' | ||
|
||
If you want to you can also use the ISO 639-2 three-letter language codes instead of | ||
the ISO 639-1 two-letter codes. (They are here called alpha3 codes.) | ||
|
||
use Symfony\Component\Intl\Languages; | ||
|
||
\Locale::setDefault('en'); | ||
|
||
$languages = Languages::getAlpha3Names(); | ||
// ('languageCode' => 'languageName') | ||
// => ['abk' => 'Abkhazian', 'ace' => 'Achinese', ...] | ||
|
||
$language = Languages::getAlpha3Name('fra'); | ||
// => 'French' | ||
|
||
All methods accept the translation locale as the last, optional parameter, | ||
which defaults to the current default locale:: | ||
|
||
|
@@ -94,6 +108,16 @@ 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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
$isValidLanguage = Languages::alpha3CodeExists($alpha3Code); | ||
|
||
You may convert codes between two-letter ISO 639-1 (alpha2) and three-letter ISO 639-2 (alpha3) codes: | ||
|
||
$alpha3Code = Languages::getAlpha3Code($alpha2Code); | ||
|
||
$alpha2Code = Languages::getAlpha2Code($alpha3Code); | ||
|
||
.. versionadded:: 4.3 | ||
|
||
The ``Languages`` class was introduced in Symfony 4.3. | ||
|
@@ -137,34 +161,57 @@ Country Names | |
~~~~~~~~~~~~~ | ||
|
||
The ``Countries`` class provides access to the name of all countries according | ||
to the `ISO 3166-1 alpha-2`_ list of officially recognized countries and | ||
territories:: | ||
to the `ISO 3166-1 alpha-2`_ list and the `ISO 3166-1 alpha-3`_ list | ||
of officially recognized countries and territories:: | ||
|
||
use Symfony\Component\Intl\Countries; | ||
|
||
\Locale::setDefault('en'); | ||
|
||
// Indexed with alpha-2 | ||
$countries = Countries::getNames(); | ||
// ('countryCode' => 'countryName') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps mention "alpha2" here to reduce comments, e.g. |
||
// => ['AF' => 'Afghanistan', 'AX' => 'Åland Islands', ...] | ||
|
||
// Indexed with alhpa-3 | ||
$countries = Countries::getAlpha3Names(); | ||
// ('countryCode' => 'countryName') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
// => ['AFG' => 'Afghanistan', 'ALA' => 'Åland Islands', ...] | ||
|
||
$country = Countries::getName('GB'); | ||
// => 'United Kingdom' | ||
|
||
$country = Countries::getAlpha3Name('NOR'); | ||
// => 'Norway' | ||
|
||
All methods accept the translation locale as the last, optional parameter, | ||
which defaults to the current default locale:: | ||
|
||
$countries = Countries::getNames('de'); | ||
// => ['AF' => 'Afghanistan', 'EG' => 'Ägypten', ...] | ||
|
||
$countries = Countries::getAlpha3Names('de'); | ||
// => ['AFG' => 'Afghanistan', 'EGY' => 'Ägypten', ...] | ||
|
||
$country = Countries::getName('GB', 'de'); | ||
// => 'Vereinigtes Königreich' | ||
|
||
$country = Countries::getName('GBR', 'de'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// => 'Vereinigtes Königreich' | ||
|
||
If the given country code 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 country code is valid:: | ||
|
||
$isValidCountry = Countries::exists($countryCode); | ||
$isValidCountry = Countries::exists($alpha2Code); | ||
|
||
$isValidCountry = Countries::alpha3CodeExists($alpha2Code); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would add a paragraph in between like languages does
|
||
|
||
You may convert codes between two-letter alpha2 and three-letter alpha3 codes: | ||
|
||
$alpha3Code = Countries::getAlpha3Code($alpha2Code); | ||
|
||
$alpha2Code = Countries::getAlpha2Code($alpha3Code); | ||
|
||
.. versionadded:: 4.3 | ||
|
||
|
@@ -356,5 +403,6 @@ Learn more | |
.. _ICU library: http://site.icu-project.org/ | ||
.. _`Unicode ISO 15924 Registry`: https://www.unicode.org/iso15924/iso15924-codes.html | ||
.. _`ISO 3166-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 | ||
.. _`ISO 3166-1 alpha-3`: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 | ||
.. _`UTC/GMT time offsets`: https://en.wikipedia.org/wiki/List_of_UTC_time_offsets | ||
.. _`daylight saving time (DST)`: https://en.wikipedia.org/wiki/Daylight_saving_time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.