xdg/locale

PHP library to work with POSIX locale identifiers.

0.1.0 2022-10-12 19:03 UTC

This package is auto-updated.

Last update: 2024-11-15 13:54:18 UTC


README

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'