Skip to content
/ locale Public

PHP library to work with POSIX locale identifiers.

License

Notifications You must be signed in to change notification settings

php-xdg/locale

Repository files navigation

xdg/locale

codecov

PHP library to work with POSIX locale identifiers.

Installation

composer require xdg/locale

Usage

Constructing locale objects

use Xdg\Locale\Locale;

// from a POSIX locale identifier
$locale = Locale::of('ca_ES@valencia');
// from an IETF (BCP47) language tag
$locale = Locale::of('zh-Hans-CN');
// On Windows, windows-specific locale identifiers are accepted
$locale = Locale::of('French_France.1252');

Locale matching

Locale matching is performed using the algorithm described in the XDG Desktop Entry specification.

use Xdg\Locale\Locale;

$locale = Locale::of('fr_FR.UTF-8')
$locale->matches('fr'); // => true
$locale->matches('fr_BE'); // => false

Use Locale::select() to select the best match from a list of candidates.

use Xdg\Locale\Locale;

$locale = Locale::of('fr_FR.UTF-8')
$locale->select(['fr_CA', 'fr_BE', 'fr']); // => 'fr'

About

PHP library to work with POSIX locale identifiers.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages