PHPackages                             gettext/languages - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. gettext/languages

ActiveLibrary[Localization &amp; i18n](/categories/localization)

gettext/languages
=================

gettext languages with plural rules

2.12.2(2mo ago)7530.3M—1%1010MITPHPPHP &gt;=5.3CI passing

Since Feb 13Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/php-gettext/Languages)[ Packagist](https://packagist.org/packages/gettext/languages)[ Docs](https://github.com/php-gettext/Languages)[ Fund](https://paypal.me/mlocati)[ GitHub Sponsors](https://github.com/mlocati)[ RSS](/packages/gettext-languages/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (28)Used By (10)

[![Tests](https://github.com/php-gettext/Languages/actions/workflows/tests.yml/badge.svg)](https://github.com/php-gettext/Languages/actions/workflows/tests.yml)

gettext language list automatically generated from CLDR data
============================================================

[](#gettext-language-list-automatically-generated-from-cldr-data)

Static usage
------------

[](#static-usage)

To use the languages data generated from this tool you can use the `bin/export-plural-rules` command.

#### Export command line options

[](#export-command-line-options)

`export-plural-rules` supports the following options:

- `--us-ascii`If specified, the output will contain only US-ASCII characters. If not specified, the output charset is UTF-8.
- `--languages=[,,...]]``--language=[,,...]]`Export only the specified language codes. Separate languages with commas; you can also use this argument more than once; it's case insensitive and accepts both '\_' and '-' as locale chunks separator (eg we accept `it_IT` as well as `it-it`). If this option is not specified, the result will contain all the available languages.
- `--reduce=yes|no`If set to yes the output won't contain languages with the same base language and rules. For instance `nl_BE` (`Flemish`) will be omitted because it's the same as `nl` (`Dutch`). Defaults to `no` if `--languages` is specified, to `yes` otherwise.
- `--parenthesis=yes|no`If set to no, extra parenthesis will be omitted in generated plural rules formulas. Those extra parenthesis are needed to create a PHP-compatible formula. Defaults to `yes`
- `--output=`If specified, the output will be saved to ``. If not specified we'll output to standard output.

#### Export formats

[](#export-formats)

`export-plural-rules` can generate data in the following formats:

- `json`: compressed JSON data

    ```
    export-plural-rules json
    ```
- `prettyjson`: uncompressed JSON data

    ```
    export-plural-rules prettyjson
    ```
- `html`: html table ([see the result](https://php-gettext.github.io/Languages/))

    ```
    export-plural-rules html
    ```
- `php`: build a php file that can be included

    ```
    export-plural-rules --output=yourfile.php php
    ```

    Then you can use that generated file in your php scripts:

    ```
    $languages = include 'yourfile.php';
    ```
- `ruby`: build a ruby file that can be included

    ```
    export-plural-rules --parenthesis=no --output=yourfile.rb ruby
    ```

    Then you can use that generated file in your ruby scripts:

    ```
    require './yourfile.rb'
    PLURAL_RULES['en']
    ```
- `xml`: generate an XML document ([here you can find the xsd XML schema](https://php-gettext.github.io/Languages/GettextLanguages.xsd))

    ```
    export-plural-rules xml
    ```
- `po`: generate the gettext .po headers for a single language

    ```
    export-plural-rules po --language=YourLanguageCode
    ```

Dynamic usage
-------------

[](#dynamic-usage)

#### With Composer

[](#with-composer)

You can use [Composer](https://getcomposer.org/) to include this tool in your project. Simply launch `composer require gettext/languages` or add `"gettext/languages": "*"` to the `"require"` section of your `composer.json` file.

#### Without Composer

[](#without-composer)

If you don't use composer in your project, you can download this package in a directory of your project and include the autoloader file:

```
require_once 'path/to/src/autoloader.php';
```

#### Main methods

[](#main-methods)

The most useful functions of this tools are the following

```
$allLanguages = Gettext\Languages\Language::getAll();
...
$oneLanguage = Gettext\Languages\Language::getById('en_US');
...
```

`getAll` returns a list of `Gettext\Languages\Language` instances, `getById` returns a single `Gettext\Languages\Language` instance (or `null` if the specified language identifier is not valid).

The main properties of the `Gettext\Languages\Language` instances are:

- `id`: the normalized language ID (for instance `en_US`)
- `name`: the language name (for instance `American English` for `en_US`)
- `supersededBy`: the code of a language that supersedes this language code (for instance, `jw` is superseded by `jv` to represent the Javanese language)
- `script`: the script name (for instance, for `zh_Hans` - `Simplified Chinese` - the script is `Simplified Han`)
- `territory`: the name of the territory (for instance `United States` for `en_US`)
- `baseLanguage`: the name of the base language (for instance `English` for `en_US`)
- `formula`: the [gettext formula](https://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Plural-forms.html) to distinguish between different plural rules. For instance `n != 1`
- `categories`: the plural cases applicable for this language. It's an array of `Gettext\Languages\Category` instances. Each instance has these properties:
    - `id`: can be (in this order) one of `zero`, `one`, `two`, `few`, `many` or `other`. The `other` case is always present.
    - `examples`: a representation of some values for which this plural case is valid (examples are simple numbers like `1` or complex ranges like `0, 2~16, 100, 1000, 10000, 100000, 1000000, …`)

Is this data correct?
---------------------

[](#is-this-data-correct)

Yes - as far as you trust the [Unicode CLDR](http://cldr.unicode.org) project.

The conversion from CLDR to gettext includes also [a lot of tests](https://travis-ci.org/php-gettext/Languages) to check the results. And all passes 😉.

Reference
---------

[](#reference)

#### CLDR

[](#cldr)

The [CLDR specifications](https://unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules) define the following variables to be used in the CLDR plural formulas:

- `n`: absolute value of the source number (integer and decimals) (eg: `9.870` =&gt; `9.87`)
- `i`: integer digits of n (eg: `9.870` =&gt; `9`)
- `v`: number of visible fraction digits in n, with trailing zeros (eg: `9.870` =&gt; `3`)
- `w`: number of visible fraction digits in n, without trailing zeros (eg: `9.870` =&gt; `2`)
- `f`: visible fractional digits in n, with trailing zeros (eg: `9.870` =&gt; `870`)
- `t`: visible fractional digits in n, without trailing zeros (eg: `9.870` =&gt; `87`)
- `c`: exponent of the power of 10 used in compact decimal formatting (eg: `98c7` =&gt; `7`)
- `e`: synonym for `c`

#### gettext

[](#gettext)

The [gettext specifications](https://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Plural-forms.html) define the following variables to be used in the gettext plural formulas:

- `n`: unsigned long int

### Conversion CLDR &gt; gettext

[](#conversion-cldr--gettext)

CLDR variablegettext equivalent`n``n``i``n``v``0``w``0``f`*empty*`t`*empty*`c`*empty*`e`*empty*Parenthesis in ternary operators
--------------------------------

[](#parenthesis-in-ternary-operators)

The generated gettext formulas contain some extra parenthesis, in order to avoid problems in some programming language. For instance, let's assume we have this formula: `(0 == 0) ? 0 : (0 == 1) ? 1 : 2`

- [in C it evaluates to `0`](http://codepad.org/Epw5WkmJ) since is the same as `(0 == 0) ? 0 : ((0 == 1) ? 1 : 2)`
- [in Java it evaluates to `0`](https://ideone.com/vbRHjW) since is the same as `(0 == 0) ? 0 : ((0 == 1) ? 1 : 2)`
- [in JavaScript it evaluates to `0`](https://jsfiddle.net/7fnxa599/) since is the same as `(0 == 0) ? 0 : ((0 == 1) ? 1 : 2)`
- [in PHP it evaluates to `2`](https://3v4l.org/QAAnA) since is the same as `((0 == 0) ? 0 : (0 == 1)) ? 1 : 2`

So, in order to avoid problems, instead of a simple `a ? 0 : b ? 1 : 2`the resulting formulas will be in this format: `a ? 0 : (b ? 1 : 2)`

Contributing
------------

[](#contributing)

### Generating the CLDR data

[](#generating-the-cldr-data)

This repository uses the CLDR data, including American English (`en_US`) json files. In order to generate this data, you can use the `bin/import-cldr-data` CLI command.

Support this project
--------------------

[](#support-this-project)

You can offer me a [monthy coffee](https://github.com/sponsors/mlocati) or a [one-time coffee](https://paypal.me/mlocati) 😉

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance83

Actively maintained with recent releases

Popularity62

Solid adoption and visibility

Community28

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 94.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~212 days

Recently: every ~306 days

Total

20

Last Release

84d ago

Major Versions

1.0.0 → 2.0.02015-02-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e9d7ece045fc89575e083ee4852edf31218df403c84f41a0de01863dae982f5?d=identicon)[mlocati](/maintainers/mlocati)

---

Top Contributors

[![mlocati](https://avatars.githubusercontent.com/u/928116?v=4)](https://github.com/mlocati "mlocati (172 commits)")[![MichaelHoste](https://avatars.githubusercontent.com/u/529357?v=4)](https://github.com/MichaelHoste "MichaelHoste (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![web-flow](https://avatars.githubusercontent.com/u/19864447?v=4)](https://github.com/web-flow "web-flow (2 commits)")[![nijel](https://avatars.githubusercontent.com/u/212189?v=4)](https://github.com/nijel "nijel (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![damnedest](https://avatars.githubusercontent.com/u/246702?v=4)](https://github.com/damnedest "damnedest (1 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")

---

Tags

phplocalizationinternationalizationi18nunicodetranslationslanguagel10ntranslatelanguagespluralcldrpluralsplural rules

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gettext-languages/health.svg)

```
[![Health](https://phpackages.com/badges/gettext-languages/health.svg)](https://phpackages.com/packages/gettext-languages)
```

###  Alternatives

[punic/punic

PHP-Unicode CLDR

1542.9M29](/packages/punic-punic)[fisharebest/localization

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

3191.1k2](/packages/fisharebest-localization)[jrmajor/fluent

Fluent localization system for PHP

2716.9k5](/packages/jrmajor-fluent)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)[jrmajor/laravel-fluent

Fluent translations for Laravel

208.4k](/packages/jrmajor-laravel-fluent)[tigrov/yii2-country

Country data for Yii2 using Intl extension and more.

151.1k](/packages/tigrov-yii2-country)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
