Download the PHP package whitecube/lingua without Composer
On this page you can find all versions of the php package whitecube/lingua. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download whitecube/lingua
More information about whitecube/lingua
Files in whitecube/lingua
Package lingua
Short Description A PHP language codes converter, from and to the most common formats (ISO, W3C, PHP and human-readable names).
License MIT
Informations about the package lingua
Lingua - Language Codes Converter
This package will convert languages from and to some common formats (ISO codes, W3C standards, PHP localization strings), including human-readable strings.
Installation
composer require whitecube/lingua
Content
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.
Usage
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".
Setters
Formatting
Default formatting
Lingua instances can be automatically transformed to strings without calling any formatting method.
The default format is set to w3c
, this means you can use Lingua instances as strings and the toW3C()
method will be called out of the box.
You can change this default behavior by calling the static setFormat
method. Available formats are: name
, native
, iso-639-1
, iso-639-2t
, iso-639-2b
, iso-639-3
, w3c
and php
.
Additionally it is also possible to specify a desired format during the instantiation of Lingua. This will always ignore the default formatting, even if you just called the static setFormat
method.
This behavior is also possible with the static create
methods. You can specify the desired formatting as second parameter.
Registering custom languages
Sometimes you'll want to add new languages to the built-in languages repository in order to recognize them later on. Of course, if said languages should be added to the package, you should consider contributing to this repo. In the meantime you can also add them from your code thanks to the LanguagesRepository::register()
method.
This will not modify the ./languages.php
file! Registered languages are only stored in memory.
Contributing
Your help is precious in order to make this package more accurate! You can contribute on two levels.
Working on core features
In order to add new features, only well-documented and tested pull-requests will be accepted.
Please open or comment existing issues on this repository in order to report bugs. If you're sure about what you're doing, you can send a pull-request.
Maintaining the languages repository
There are currently some languages marked with a // TODO
comment in the ./languages.php
file. This means we probably didn't find enough information about these languages. You know how to fill the gaps? Please let us know! You can open an issue, make a pull-request or contact us on any available platform.
And of course you can also add new languages to the repository, but only if you're sure about the terminology.
Please beware that changing some existing values in the languages.php
file can result in some PHPUnit test failures, so make sure to run the tests and update them accordingly before submitting your changes.
Thank you!
💖 Sponsorships
If you are reliant on this package in your production applications, consider sponsoring us! It is the best way to help us keep doing what we love to do: making great open source software.
All versions of lingua with dependencies
ext-mbstring Version *