phospr/locale

A simple PHP Locale Value Object

Maintainers

Details

github.com/phospr/locale

Source

Issues

Installs: 2 000

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 3

Open Issues: 0

pkg:composer/phospr/locale

v1.0.0 2016-03-14 16:02 UTC

This package is auto-updated.

Last update: 2025-10-06 12:57:11 UTC


README

Build Status Coverage Status

Simple PHP Locale ValueObject

Usage

use Phospr\Locale;

echo Locale::fromString('en_US'); // en_US
echo Locale::fromCountrySlashLanguage('ca/fr'); // fr_CA

Formatting

Use:

  • %L For uppercase language code
  • %l For lowercase language code
  • %C For uppercase country code
  • %c For lowercase country code

Note:

  • any other combination of %{:char:} will throw an InvalidArgumentException unless the % is escaped with \
  • to get a \ You will need to double escape ( \\\ )

Examples:

echo Locale::fromString('se_FI')->format('%L_%c'); // SE_fi
echo Locale::fromString('se_FI')->format('%C/%s'); // FI/se
echo Locale::fromString('se_FI')->format('%c/%s'); // fi/se
echo Locale::fromString('se_FI')->format('%c\\\%s'); // fi\se

Installation

composer require phospr/locale

Sources

Language data from http://stackoverflow.com/a/4900304

Country data from http://country.io/data/