xdg/locale

PHP library to work with POSIX locale identifiers.

Installs: 74

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/xdg/locale

0.1.0 2022-10-12 19:03 UTC

This package is auto-updated.

Last update: 2025-10-15 15:54:14 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'