This package will convert languages from and to some common formats (ISO codes, W3C standards, PHP localization strings), including human-readable strings.
composer require whitecube/lingua
The package currently supports over 220 languages. Most living languages are included, with country codes, names and possible alphabet sets (Latin, Cyrillic, Arabic, ...).
Available input and output formats are:
name
: The english name of the language (most of the time).native
: The autonym of the language.ISO-639-1
: The official two-letter code for the language. Some languages do not have this code.ISO-639-2t
: An official three-letter code for terminology applications (ISO 639-2/T) for the language.ISO-639-2b
: An official three-letter code for bibliographic applications (ISO 639-2/B) for the language.ISO-639-3
: The official three-letter code. This is also the most common terminology and therefore the most complete language representation. In most cases, this is the same format asISO-639-2t
, except for macrolanguages.W3C
: A valid string as described by the BCP 47 specification (used in the W3C's language attributes recommendations).PHP
: A string with the appropriate format for PHP'ssetlocale()
. This does not check if the locale is available on your server.
Note on macrolanguages: The ISO-639-3
output will also indicate the amount of sub-languages represented with the same ISO code.
The Lingua converter works in two stages: first you'll need to instantiate it by providing the original format, than you can convert this string as many times as you want to any of the available formats.
Note: you can instanciate some languages with their deprecated ISO code. For example, you can instanciate Hebrew with the ISO 639_1 code "iw" instead of "he".
use WhiteCube\Lingua\Service as Lingua;
// Create a converter, without knowing the original format (this will try to guess it for you)
$language = Lingua::create('en_GB');
// Create a converter from a language name
$language = Lingua::createFromName('french');
$language = (new Lingua())->fromName('german');
// Create a converter from a language's native name
$language = Lingua::createFromNative('nederlands');
$language = (new Lingua())->fromNative('magyar');
// Create a converter from a ISO 639-1 code
$language = Lingua::createFromISO_639_1('mk');
$language = (new Lingua())->fromISO_639_1('ko');
// Create a converter from a ISO 639-2t code
$language = Lingua::createFromISO_639_2t('heb');
$language = (new Lingua())->fromISO_639_2t('gle');
// Create a converter from a ISO 639-2b code
$language = Lingua::createFromISO_639_2b('her');
$language = (new Lingua())->fromISO_639_2b('iku');
// Create a converter from a ISO 639-3 code
$language = Lingua::createFromISO_639_3('aze + 2');
$language = (new