2017 © Pedro Peláez
 

library localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

image

fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  • Tuesday, January 16, 2018
  • by fisharebest
  • Repository
  • 2 Watchers
  • 17 Stars
  • 10,181 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 25 Versions
  • 5 % Grown

The README.md

phpunit phpstan phpcs codecov StyleCI Code Climate, (*1)

Localization standards and data

This package combines localization data from many standards, including the Unicode CLDR, RFC5646 / IANA subtag registry, ISO-3166, ISO-639, ISO-15924, etc., to help you produce applications that behave nicely for visitors from around the world., (*2)

Includes definitions for over 800 locales., (*3)

Locales, languages, scripts and territories

A locale consists of three things: a language, a script and a territory. Scripts and territories are often implicit from the language., (*4)

Normally you would just need to work with locales, and can ignore languages and scripts., (*5)

``` php $locale = new LocaleJa; // Create a locale for Japanese. $locale = Locale::create('ja'); // Create a locale for Japanese, from its code., (*6)

$locale->code(); // "ja_JP" (territories are always included in locale codes) $locale->languageTag(); // "ja" (redundant territories are omitted in tags) $locale->endonym(); // "日本語" (Japanese name for Japanese), (*7)

// Languages - extract from the locale, or create with "new LanguageXx" $locale->language(); // LanguageJa $locale->language()->code(); // "ja" (ISO-639 code), (*8)

// Scripts - extract from the locale, or create with "new ScriptXxxx" $locale->script(); // ScriptJpan $locale->script()->code(); // "Jpan" (ISO-15924 code) $locale->script()->direction(); // "ltr" (left to right), (*9)

// Territories - extract from the locale, or create with "new TerritoryXx" $locale->territory(); // TerritoryJp $locale->territory()->code(); // "JP" (ISO-3166 code), (*10)

// A few locales can also specify variants. $locale = new LocaleCaValencia; // The Valencian dialect of Catalan $locale->variant(); // VariantValencia $locale->variant()->code(); // "valencia", (*11)


Localization ============ Create a locale and use it to localize data in your application. ``` php // Many ways to create locales $locale = new LocaleEnGb; $locale = Locale::create('en-GB'); // Use upper/lower case, hyphens/underscores/@ $locale = Locale::httpAcceptLanguage($_SERVER, $available_locales, $default_locale); // Markup for HTML elements containing this locale $locale->htmlAttributes(); // lang="ar" dir="rtl" // Is text written left-to-right or right-to-left $locale->direction(); // "ltr" or "rtl" // Days of the week. $locale->firstDay(); // 0=Sunday, 1=Monday, etc. $locale->weekendStart(); // 0=Sunday, 1=Monday, etc. $locale->weekendEnd(); // 0=Sunday, 1=Monday, etc. // Measurement systems and paper sizes. $locale->measurementSystem(); // "metric", "UK" or "US" $locale->paperSize(); // "A4" or "US-Letter" // Formatting numbers $locale = new LocaleGr; // Gujarati $locale->digits('2014'); // "૨૦૧૪" $locale = new LocaleItCh; // Swiss Italian $locale->number('12345678.9'); // "12'345'678.9" $locale->percent(0.123); // "12.3%" // To sort data properly in MySQL, you need to specify a collation sequence. // See https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-sets.html $locale->collation(); // "unicode_ci", "swedish_ci", etc.

Translation

Plural rules are defined for each locale. This example shows that although English and French both have two plural forms, English considers zero as plural, while French considers it to be singular., (*12)

``` php $locale = new LocaleEn; $locale->pluralRule()->plurals(); // 2 (English has two plural forms) $locale->pluralRule()->plural(0); // 1 (zero is plural in English "zero apples") $locale = new LocaleFr; $locale->pluralRule()->plurals(); // 2 (French also has two plural forms) $locale->pluralRule()->plural(0); // 0 (zero is singular in French "zero apple"), (*13)


Note that some plural definitions in CLDR differ to those traditionally used by `gettext`. We use the gettext versions for br, fa, fil, he, lv, mk, pt and se. Translation functions work the same as `gettext`. ``` php // We need to translate into French $locale = new LocaleFr; // Create the translation $translation = new Translation('/path/to/fr.mo'); // Can use .CSV, .PHP, .PO and .MO files // Create the translator $translator = new Translator($translation->asArray(), $locale->pluralRule()); // Use the translator $translator->translate('the fish'); // "le poisson" $translator->translateContext('noun', 'fish'); // "poisson" $translator->translateContext('verb', 'fish'); // "pêcher" $translator->plural('%d fish', '%d fishes', 4); // "%d poissons"

TIP: If your translations are stored in more than one file, you can merge them easily., (*14)

// Create the translation
$translation1 = new Translation('/path/to/core/fr.mo');
$translation2 = new Translation('/path/to/extra/fr.mo');
// Create the translator
$translator = new Translator(array_merge($translation1->asArray(), $translation2->asArray()), $locale->pluralRule());

TIP: Loading translations from .PHP files is a little faster than loading them from .MO files. You can convert and/or cache them using this approach., (*15)

$translation = new Translation('/path/to/fr.mo');
file_put_contents('/path/to/fr.php', '<?php return ' . var_export($translations->asArray(), true) . ';');

Updates welcome

Please provide references to sources, such as:, (*16)

The Versions

16/01 2018

dev-master

9999999-dev https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

16/01 2018

1.10.3

1.10.3.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

30/10 2017

1.10.2

1.10.2.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

24/10 2017

dev-develop

dev-develop https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

24/10 2017

1.10.1

1.10.1.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

02/06 2016

1.10.0

1.10.0.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

26/03 2016

1.9.0

1.9.0.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

26/03 2016

1.8.0

1.8.0.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

27/11 2015

1.7.0

1.7.0.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

14/09 2015

1.6.0

1.6.0.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

14/09 2015

1.5.1

1.5.1.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

30/06 2015

1.5.0

1.5.0.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

06/04 2015

1.4.1

1.4.1.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

27/03 2015

1.4.0

1.4.0.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

23/03 2015

1.3.2

1.3.2.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

21/03 2015

1.3.1

1.3.1.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

20/03 2015

1.3.0

1.3.0.0 https://github.com/fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

language translation locale i18n localization translate gettext l10n script cldr

19/03 2015

1.2.0

1.2.0.0 https://github.com/fisharebest/localization

A lightweight implementation of the Unicode Common Locale Data Repository (CLDR).

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

locale i18n localization unicode l10n

15/03 2015

1.1.2

1.1.2.0 https://github.com/fisharebest/localization

A lightweight implementation of the Unicode Common Locale Data Repository (CLDR).

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

locale i18n localization unicode l10n

13/03 2015

1.1.1

1.1.1.0 https://github.com/fisharebest/localization

A lightweight implementation of the Unicode Common Locale Data Repository (CLDR).

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

locale i18n localization unicode l10n

12/03 2015

1.1.0

1.1.0.0 https://github.com/fisharebest/localization

A lightweight implementation of the Unicode Common Locale Data Repository (CLDR).

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

locale i18n localization unicode l10n

12/03 2015

1.0.3

1.0.3.0 https://github.com/fisharebest/localization

A lightweight implementation of the Unicode Common Locale Data Repository (CLDR).

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

locale i18n localization unicode l10n

11/03 2015

1.0.2

1.0.2.0 https://github.com/fisharebest/localization

A lightweight implementation of the Unicode Common Locale Data Repository (CLDR).

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

locale i18n localization unicode l10n

26/02 2015

1.0.1

1.0.1.0 https://github.com/fisharebest/localization

A lightweight implementation of the Unicode Common Locale Data Repository (CLDR).

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

locale i18n localization unicode l10n

24/02 2015

1.0.0

1.0.0.0 https://github.com/fisharebest/localization

A lightweight implementation of the Unicode Common Locale Data Repository (CLDR).

  Sources   Download

GPL-3.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Greg Roach

locale i18n localization unicode l10n