PHPackages                             josantonius/languagecode - 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. josantonius/languagecode

Abandoned → [josantonius/language-code](/?search=josantonius%2Flanguage-code)Library

josantonius/languagecode
========================

PHP library to get language name from code.

v2.0.0(3y ago)58.8k3MITPHPPHP ^8.0

Since Jan 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/josantonius/php-language-code)[ Packagist](https://packagist.org/packages/josantonius/languagecode)[ GitHub Sponsors](https://github.com/Josantonius)[ RSS](/packages/josantonius-languagecode/feed)WikiDiscussions main Synced 2mo ago

READMEChangelog (10)Dependencies (3)Versions (11)Used By (0)

PHP LanguageCode library
========================

[](#php-languagecode-library)

[![Latest Stable Version](https://camo.githubusercontent.com/6369e763f6322767b213b17598084443bd0728307a383ead9efd6986c419420e/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f6c616e67756167652d636f64652f762f737461626c65)](https://packagist.org/packages/josantonius/language-code)[![License](https://camo.githubusercontent.com/5246345dfe78341ac41f2adfcd68832ee09e6f419d90de7c5614406c2cb5f595/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f6c616e67756167652d636f64652f6c6963656e7365)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/e45b6f5361006724e0fd0aeeadfe2a0d4f738e9076d999699b62a57908bdf134/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f6c616e67756167652d636f64652f646f776e6c6f616473)](https://packagist.org/packages/josantonius/language-code)[![CI](https://github.com/josantonius/php-language-code/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/josantonius/php-language-code/actions/workflows/ci.yml)[![CodeCov](https://camo.githubusercontent.com/588be217765f121fa0dbf467fd3006f3a3d8961e52f915570ed1aa98511fa49e/68747470733a2f2f636f6465636f762e696f2f67682f6a6f73616e746f6e6975732f7068702d6c616e67756167652d636f64652f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/josantonius/php-language-code)[![PSR1](https://camo.githubusercontent.com/b502a899c9aec217e98971160f816f87346be272cf1a25cfa4793f2ee724bfc8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d312d6635373034362e737667)](https://www.php-fig.org/psr/psr-1/)[![PSR4](https://camo.githubusercontent.com/d1c090de87e968254a6658528f3bfe9c9dad422d6047fd1323dc211560182c01/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d342d3962353962362e737667)](https://www.php-fig.org/psr/psr-4/)[![PSR12](https://camo.githubusercontent.com/19c529c6dc0656dcc2a16c1a84af450b7bd0dc7b0571b8f17e4fc9f2414f8821/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d31322d3161626339632e737667)](https://www.php-fig.org/psr/psr-12/)

**Translations**: [Español](.github/lang/es-ES/README.md)

PHP library to get language name from code.

---

- [Requirements](#requirements)
- [Installation](#installation)
- [Available Classes](#available-classes)
    - [LanguageCode Class](#languagecode-class)
    - [LanguageCodeCollection Class](#languagecodecollection-class)
- [Usage](#usage)
- [List in JSON format](#list-in-json-format)
- [Tests](#tests)
- [TODO](#todo)
- [Changelog](#changelog)
- [Contribution](#contribution)
- [Sponsor](#sponsor)
- [License](#license)

---

Requirements
------------

[](#requirements)

Operating System: Linux | Windows.

PHP versions: 8.0 | 8.1 | 8.2.

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

[](#installation)

The preferred way to install this extension is through [Composer](http://getcomposer.org/download/).

To install **PHP LanguageCode library**, simply:

```
composer require josantonius/language-code
```

The previous command will only install the necessary files, if you prefer to **download the entire source code** you can use:

```
composer require josantonius/language-code --prefer-source
```

You can also **clone the complete repository** with Git:

```
clone https://github.com/josantonius/php-language-code.git
```

Available Classes
-----------------

[](#available-classes)

### LanguageCode Class

[](#languagecode-class)

`Josantonius\LanguageCode\LanguageCode`

Get all language codes as array:

```
public static function all(): array;
```

Get language code from language name:

```
public static function getCode(string $languageName): string|null;
```

Get language name from language code:

```
public static function getName(string $languageCode): string|null;
```

### LanguageCodeCollection Class

[](#languagecodecollection-class)

`Josantonius\LanguageCode\LanguageCodeCollection`

Get all language codes as array:

```
public static function all(): array
```

Get language code from language name:

```
public static function getCode(string $languageName): string|null
```

Get language name from language code:

```
public static function getName(string $languageCode): string|null
```

Usage
-----

[](#usage)

Example of use for this library:

### Get all language codes as array

[](#get-all-language-codes-as-array)

```
use Josantonius\LanguageCode\LanguageCode;

$languageCode = new LanguageCode();

$languageCode->all();
```

```
use Josantonius\LanguageCode\LanguageCodeCollection;

LanguageCodeCollection::all();
```

Result:

```
[
    'aa' => 'Afar',
    'ab' => 'Abkhazian',
    'af' => 'Afrikaans',
    'am' => 'Amharic',
    'ar' => 'Arabic',
    'ar-ae' => 'Arabic (U.A.E.)',
    'ar-bh' => 'Arabic (Bahrain)',
    'ar-dz' => 'Arabic (Algeria)',
    'ar-eg' => 'Arabic (Egypt)',
    'ar-iq' => 'Arabic (Iraq)',
    (...)
]
```

### Get language code from language name

[](#get-language-code-from-language-name)

```
use Josantonius\LanguageCode\LanguageCode;

$languageCode = new LanguageCode();

$languageCode->getCode('Spanish'); // es
```

```
use Josantonius\LanguageCode\LanguageCodeCollection;

LanguageCodeCollection::getCode('Turkish'); // tr
```

### Get language name from language code

[](#get-language-name-from-language-code)

```
use Josantonius\LanguageCode\LanguageCode;

$languageCode = new LanguageCode();

$languageCode->getName('eo'); // Esperanto
```

```
use Josantonius\LanguageCode\LanguageCodeCollection;

LanguageCodeCollection::getName('de'); // German
```

List in JSON format
-------------------

[](#list-in-json-format)

[Go to the resource](https://gist.github.com/josantonius/b455e315bc7f790d14b136d61d9ae469).

Tests
-----

[](#tests)

To run [tests](tests) you just need [composer](http://getcomposer.org/download/)and to execute the following:

```
git clone https://github.com/josantonius/php-language-code.git
```

```
cd php-language-code
```

```
composer install
```

Run unit tests with [PHPUnit](https://phpunit.de/):

```
composer phpunit
```

Run code standard tests with [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer):

```
composer phpcs
```

Run [PHP Mess Detector](https://phpmd.org/) tests to detect inconsistencies in code style:

```
composer phpmd
```

Run all previous tests:

```
composer tests
```

TODO
----

[](#todo)

- Add new feature
- Improve tests
- Improve documentation
- Improve English translation in the README file
- Refactor code for disabled code style rules (see phpmd.xml and phpcs.xml)

Changelog
---------

[](#changelog)

Detailed changes for each release are documented in the [release notes](https://github.com/josantonius/php-language-code/releases).

Contribution
------------

[](#contribution)

Please make sure to read the [Contributing Guide](.github/CONTRIBUTING.md), before making a pull request, start a discussion or report a issue.

Thanks to all [contributors](https://github.com/josantonius/php-language-code/graphs/contributors)! ❤️

Sponsor
-------

[](#sponsor)

If this project helps you to reduce your development time, [you can sponsor me](https://github.com/josantonius#sponsor) to support my open source work 😊

License
-------

[](#license)

This repository is licensed under the [MIT License](LICENSE).

Copyright © 2017-present, [Josantonius](https://github.com/josantonius#contact)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~289 days

Recently: every ~445 days

Total

8

Last Release

1382d ago

Major Versions

1.1.6 → v2.0.02022-08-02

PHP version history (3 changes)1.0.0PHP &gt;=7.0

1.1.1PHP ^5.6 || ^7.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b221283501ec8a9cbaefaf27821a91ae8ddd33bddf1fccc6c6815b7ad216ff1?d=identicon)[Josantonius](/maintainers/Josantonius)

---

Top Contributors

[![josantonius](https://avatars.githubusercontent.com/u/18104336?v=4)](https://github.com/josantonius "josantonius (41 commits)")

---

Tags

composeriso639-1language-codelanguage-codesphpphplanguageISO 639-1language code

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/josantonius-languagecode/health.svg)

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

###  Alternatives

[felixfbecker/language-server-protocol

PHP classes for the Language Server Protocol

22476.7M6](/packages/felixfbecker-language-server-protocol)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[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)[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)

PHPackages © 2026

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