places2be/locales

Handling country codes and language codes

2.0.0 2023-05-30 09:29 UTC

This package is auto-updated.

Last update: 2024-03-30 00:25:35 UTC


README

PHP from Packagist Codacy Badge Latest Stable Version Total Downloads License

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.