places2be/locales

Handling country codes and language codes

1.9.0 2020-06-09 06:53 UTC

This package is auto-updated.

Last update: 2020-10-09 07:35:58 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. If you don't use LOCALES_IGNORE_COUNTRY_EXISTENCE by set up a country code, the script will proof if the country code exists. Ignore the check be writing:

<?php

use Places2Be\Locales\CountryCode;

$countryCode = new CountryCode('de', LOCALES_IGNORE_COUNTRY_EXISTENCE);

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. If you don't use LOCALES_IGNORE_LANGUAGE_EXISTENCE by set up a language code, the script will proof if the language code exists. Ignore the check be writing:

<?php

use Places2Be\Locales\LanguageCode;

$languageCode = new LanguageCode('de-ch', LOCALES_IGNORE_LANGUAGE_EXISTENCE);

If you want to use country-unspecific language codes like de instead of de-de you can use the constant LOCALES_ALLOW_COUNTRY_UNSPECIFIC_LANGUAGE_CODES.

If you want to make use of all constants remember to separate them with a pipe |.

Help

If you have any questions feel free to contact us under places2belocales@bitandblack.com.