places2be / locales
Handling country codes and language codes
Fund package maintenance!
Buymeacoffee
Requires
- php: >=8.2
- ext-mbstring: *
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^11.0
- rector/rector: ^1.0
- symfony/var-dumper: ^7.0
- symplify/easy-coding-standard: ^12.0
README
Places2Be Locales
Handling country codes and language codes by storing them in an object.
Installation
This library is made for the use with Composer. Add it to your project by running $ composer require places2be/locales
.
Usage
Country codes
Set up a country code like that:
<?php
use Places2Be\Locales\CountryCode;
$countryCode = new CountryCode('de');
The script will only accept country codes having a length of two characters and will throw an InvalidCountryCode
exception otherwise.
Per default, the script will proof if the country code exists. Ignore the check be writing:
<?php
use Places2Be\Locales\CountryCode;
CountryCode::ignoreCountryExistence();
$countryCode = new CountryCode('xy');
Language codes
Set up a language code like:
<?php
use Places2Be\Locales\LanguageCode;
$languageCode = new LanguageCode('de-ch');
The script will only accept language codes written like that: xx-xx
(or xxx-xx
) and will throw an InvalidLanguageCode
exception otherwise.
Per default, the script will proof if the language code exists. Ignore the check be writing:
<?php
use Places2Be\Locales\LanguageCode;
LanguageCode::ignoreLanguageExistence();
$languageCode = new LanguageCode('de-xx');
If you want to use country-unspecific language codes like de
instead of de-de
you can allow that by writing LanguageCode::allowCountryUnspecificLanguageCode()
.
Help
If you have any questions, feel free to contact us under hello@bitandblack.com
.
Further information about Bit&Black can be found under www.bitandblack.com.