Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
OskarStark merged 1 commit intosymfony:4.4fromterjebraten-certua:new-alpha3-methods
Aug 15, 2019
Merged
Changes fromall 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
54 changes: 51 additions & 3 deletionscomponents/intl.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You can also use the ISO 639-2 three-letter language codes instead ofthe 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');
// => 'French'

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

Expand All@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

:: i believe (not a format expert here :D)

OskarStark reacted with thumbs up emoji

$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.
Expand DownExpand Up@@ -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`_ listof officially recognized countries and
territories::
to the `ISO 3166-1 alpha-2`_ listand the `ISO 3166-1 alpha-3`_ list
of officially recognized countries andterritories::

use Symfony\Component\Intl\Countries;

\Locale::setDefault('en');

// Indexed with alpha-2
$countries = Countries::getNames();
// ('countryCode' => 'countryName')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

perhaps mention "alpha2" here to reduce comments, e.g.// ('alpha2Code' => 'countryName')

// => ['AF' => 'Afghanistan', 'AX' => 'Åland Islands', ...]

// Indexed with alhpa-3
$countries = Countries::getAlpha3Names();
// ('countryCode' => 'countryName')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

same// ('alpha3Code' => 'countryName')

// => ['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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

getAlpha3Name

OskarStark reacted with thumbs up emoji
// => '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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

i would add a paragraph in between like languages does

Or if you have a alpha3 country code you want to check:    $isValidCountry = Countries::alpha3CodeExists($alpha3Code);


You may convert codes between two-letter alpha2 and three-letter alpha3 codes:

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

$alpha2Code = Countries::getAlpha2Code($alpha3Code);

.. versionadded:: 4.3

Expand DownExpand Up@@ -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

[8]ページ先頭

©2009-2025 Movatter.jp