PHPackages                             whitecube/lingua - 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. whitecube/lingua

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

whitecube/lingua
================

A PHP language codes converter, from and to the most common formats (ISO, W3C, PHP and human-readable names).

1.1.1(4y ago)441.2M↓11.8%612MITPHPPHP ^7.0|^8.0

Since Jun 1Pushed 4y ago6 watchersCompare

[ Source](https://github.com/whitecube/lingua)[ Packagist](https://packagist.org/packages/whitecube/lingua)[ GitHub Sponsors](https://github.com/whitecube)[ RSS](/packages/whitecube-lingua/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (8)Used By (12)

Lingua - Language Codes Converter
=================================

[](#lingua---language-codes-converter)

[![Travis](https://camo.githubusercontent.com/20bc209719d47305a319da04a59111a3db216d645c8dff35169d6de825196ec3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7768697465637562652f6c696e6775612e737667)](https://travis-ci.org/whitecube/lingua)[![Test Coverage](https://camo.githubusercontent.com/9e3c95f69def4f7668eb5add7a8b3f8e1a78015d75cb52418a5324803ee2df49/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62326439336666333733366336333138333863632f746573745f636f766572616765)](https://codeclimate.com/github/whiteCube/lingua/test_coverage)[![GitHub release](https://camo.githubusercontent.com/8e9f2fa553e6168c14ba1355ceacc558295d2ad33c30bfa1679fcc0c67310ca9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f7768697465437562652f6c696e6775612e737667)](https://github.com/whiteCube/lingua/releases)[![Packagist](https://camo.githubusercontent.com/c747835d543128fb652a2a7df0987454d1de67ca398aae3e969625893a83a28b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7768697465437562652f4c696e6775612e737667)](https://packagist.org/packages/whitecube/lingua)[![GitHub issues](https://camo.githubusercontent.com/ebd22b0a4164705fceb9165c51e7fe5d38aee1b6d345aae25f32ac2b39efeeaa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f7768697465437562652f6c696e6775612e737667)](https://github.com/whiteCube/lingua/issues)[![GitHub pull requests](https://camo.githubusercontent.com/d7b6a392df11cbaf62189803b9ee4ab4b816f7dda13ebb26f0f9c5697a1d16ba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f7768697465437562652f6c696e6775612e737667)](https://github.com/whiteCube/lingua/pulls)[![license](https://camo.githubusercontent.com/d32b3dfc25f5d3afddb74933cbade593c570f7de0ccb685a752dc3122bf9b824/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7768697465437562652f6c696e6775612e737667)](https://github.com/whiteCube/lingua/blob/master/LICENSE)

This package will convert languages *from and to* some common formats (ISO codes, W3C standards, PHP localization strings), including human-readable strings.

Installation
------------

[](#installation)

`composer require whitecube/lingua`

Content
-------

[](#content)

The package currently supports **over 220 languages**. Most living languages are included, with country codes, names and possible alphabet sets (Latin, Cyrillic, Arabic, ...).

Available **input and output formats** are:

1. `name`: The english name of the language (most of the time).
2. `native`: The autonym of the language.
3. `ISO-639-1`: The official [two-letter code](https://www.loc.gov/standards/iso639-2/php/code_list.php) for the language. **Some languages do not have this code**.
4. `ISO-639-2t`: An official three-letter code for terminology applications (ISO 639-2/T) for the language.
5. `ISO-639-2b`: An official three-letter code for bibliographic applications (ISO 639-2/B) for the language.
6. `ISO-639-3`: The official three-letter code. This is also the most common terminology and therefore the most complete language representation. In most cases, this is the same format as `ISO-639-2t`, except for macrolanguages.
7. `W3C`: A [valid](https://r12a.github.io/app-subtags/) string as described by the BCP 47 specification (used in the [W3C](https://www.w3.org/International/questions/qa-html-language-declarations#langvalues)'s language attributes recommendations).
8. `PHP`: A string with the appropriate format for PHP's `setlocale()`. This does not check if the locale is available on your server.

**Note on macrolanguages**: The `ISO-639-3` output will also indicate the amount of sub-languages represented with the same ISO code.

Usage
-----

[](#usage)

The Lingua converter works in two stages: first you'll need to instantiate it by providing the original format, than you can convert this string as many times as you want to any of the available formats.

> Note: you can instanciate some languages with their deprecated ISO code. For example, you can instanciate Hebrew with the ISO 639\_1 code "iw" instead of "he".

### Setters

[](#setters)

```
use WhiteCube\Lingua\Service as Lingua;

// Create a converter, without knowing the original format (this will try to guess it for you)
$language = Lingua::create('en_GB');

// Create a converter from a language name
$language = Lingua::createFromName('french');
$language = (new Lingua())->fromName('german');

// Create a converter from a language's native name
$language = Lingua::createFromNative('nederlands');
$language = (new Lingua())->fromNative('magyar');

// Create a converter from a ISO 639-1 code
$language = Lingua::createFromISO_639_1('mk');
$language = (new Lingua())->fromISO_639_1('ko');

// Create a converter from a ISO 639-2t code
$language = Lingua::createFromISO_639_2t('heb');
$language = (new Lingua())->fromISO_639_2t('gle');

// Create a converter from a ISO 639-2b code
$language = Lingua::createFromISO_639_2b('her');
$language = (new Lingua())->fromISO_639_2b('iku');

// Create a converter from a ISO 639-3 code
$language = Lingua::createFromISO_639_3('aze + 2');
$language = (new Lingua())->fromISO_639_3('asm');

// Create a converter from a valid W3C language string
$language = Lingua::createFromW3C('ae');
$language = (new Lingua())->fromW3C('zh-hans-SG');

// Create a converter from a valid PHP localization string
$language = Lingua::createFromPHP('fr_BE');
$language = (new Lingua())->fromPHP('kk_Cyrl_KZ');
```

### Formatting

[](#formatting)

```
use WhiteCube\Lingua\Service as Lingua;

$language = Lingua::createFromNative('français');

// Format a language in a human readable string (the language's english name)
echo $language->toName(); // "french"

// Format a language in its native form
echo $language->toNative(); // "français"

// Format a language in a ISO 639-1 string
echo $language->toISO_639_1(); // "fr"

// Format a language in a ISO 639-2t string
echo $language->toISO_639_2t(); // "fra"

// Format a language in a ISO 639-2b string
echo $language->toISO_639_2b(); // "fre"

// Format a language in a ISO 639-3 string
echo $language->toISO_639_3(); // "fra"

// Format a language in a valid W3C language attribute string (according to BCP 47)
echo $language->toW3C(); // "fr" in this case but could be "fr-BE" if country code was specified

// Format a localization string for PHP's setlocale()
echo $language->toPHP(); // "fr" in this case but could be "fr_BE" if country code was specified
```

#### Default formatting

[](#default-formatting)

Lingua instances can be automatically transformed to strings without calling any formatting method.

The **default format** is set to `w3c`, this means you can use Lingua instances as strings and the `toW3C()` method will be called out of the box.

```
use WhiteCube\Lingua\Service as Lingua;

echo Lingua::createFromName('italian'); // "it"
```

You can change this default behavior by calling the static `setFormat` method. Available formats are: `name`, `native`, `iso-639-1`, `iso-639-2t`, `iso-639-2b`, `iso-639-3`, `w3c` and `php`.

```
use WhiteCube\Lingua\Service as Lingua;

Lingua::setFormat('native');
$language = Lingua::createFromISO_639_3('ita');
echo $language; // "italiano"

Lingua::setFormat('iso-639-1');
echo $language; // "it"
```

Additionally it is also possible to specify a desired format during the instantiation of Lingua. This **will always ignore the default formatting**, even if you just called the static `setFormat` method.

```
use WhiteCube\Lingua\Service as Lingua;

$language = new Lingua('native');
$language->fromISO_639_1('ks');
echo $language; // "कश्मीरी, كشميري‎"

// Trying to change the default formatting
Lingua::setFormat('name');

echo $language; // still "कश्मीरी, كشميري‎"
echo $language->toName(); // "kashmiri"
```

This behavior is also possible with the static `create` methods. You can specify the desired formatting as second parameter.

```
use WhiteCube\Lingua\Service as Lingua;

echo Lingua::createFromName('maltese', 'native'); // "malti"
```

Registering custom languages
----------------------------

[](#registering-custom-languages)

Sometimes you'll want to add new languages to the built-in languages repository in order to recognize them later on. Of course, if said languages should be added to the package, you should consider contributing to this repo. In the meantime you can also add them from your code thanks to the `LanguagesRepository::register()` method.

```
use WhiteCube\Lingua\Service as Lingua;
use WhiteCube\Lingua\LanguagesRepository;

// Note: all keys of the register-array showed below are optionnal.
LanguagesRepository::register([
    'name' => 'custom',
    'native' => 'custom-language',
    'iso-639-1' => 'cl',
    'iso-639-2t' => 'cla',
    'iso-639-2b' => 'cla',
    'iso-639-3' => 'cla + 2',
    'countries' => ['MY' => 'My Country'],
    'scripts' => ['latn' => 'latin', 'cyrl' => 'cyrillic']
]);

echo Lingua::createFromName('custom')->toNative(); // "custom-language"
```

This will not modify the `./languages.php` file! Registered languages are only stored in memory.

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

[](#contributing)

Your help is precious in order to make this package more accurate! You can contribute on two levels.

### Working on core features

[](#working-on-core-features)

In order to add new features, only well-documented and tested pull-requests will be accepted.

Please open or comment existing issues on this repository in order to report bugs. If you're sure about what you're doing, you can send a pull-request.

### Maintaining the languages repository

[](#maintaining-the-languages-repository)

There are currently some languages marked with a `// TODO` comment in the `./languages.php` file. This means we probably didn't find enough information about these languages. You know how to fill the gaps? Please let us know! You can open an issue, make a pull-request or contact us on any available platform.

And of course you can also add new languages to the repository, but only if you're sure about the terminology.

Please beware that changing some existing values in the `languages.php` file can result in some PHPUnit test failures, so make sure to run the tests and update them accordingly before submitting your changes.

Thank you!

💖 Sponsorships
--------------

[](#-sponsorships)

If you are reliant on this package in your production applications, consider [sponsoring us](https://github.com/sponsors/whitecube)! It is the best way to help us keep doing what we love to do: making great open source software.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity51

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 72.9% 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 ~273 days

Recently: every ~278 days

Total

7

Last Release

1635d ago

PHP version history (2 changes)1.0.0PHP ^7.0

1.1.0PHP ^7.0|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8435657?v=4)[Whitecube](/maintainers/Whitecube)[@whitecube](https://github.com/whitecube)

---

Top Contributors

[![toonvandenbos](https://avatars.githubusercontent.com/u/5635557?v=4)](https://github.com/toonvandenbos "toonvandenbos (43 commits)")[![voidgraphics](https://avatars.githubusercontent.com/u/9298484?v=4)](https://github.com/voidgraphics "voidgraphics (10 commits)")[![caugner](https://avatars.githubusercontent.com/u/495429?v=4)](https://github.com/caugner "caugner (3 commits)")[![Wirone](https://avatars.githubusercontent.com/u/600668?v=4)](https://github.com/Wirone "Wirone (3 commits)")

---

Tags

convert-languagesisolanguagelingualocaleslocalizationw3clocalizationlanguagetranslatetranslationisoconversionlocalescodesBCP-47

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/whitecube-lingua/health.svg)

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

###  Alternatives

[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[gettext/languages

gettext languages with plural rules

7530.3M11](/packages/gettext-languages)[fisharebest/localization

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

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

Simple localisation for Silverstripe

92421.6k26](/packages/tractorcow-silverstripe-fluent)[boxblinkracer/phpunuhi

Easy tool to work with translation files for validation, exports, imports and more.

83225.2k17](/packages/boxblinkracer-phpunuhi)[laravel-lang/locales

Basic functionality for working with localizations

134.5M12](/packages/laravel-lang-locales)

PHPackages © 2026

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