https://github.com/leodido/langcode-conv
Convert language codes to any available format
https://github.com/leodido/langcode-conv
conversion hacktoberfest iso639 language-codes php
Last synced: 4 months ago
JSON representation
Convert language codes to any available format
- Host: GitHub
- URL: https://github.com/leodido/langcode-conv
- Owner: leodido
- Created: 2014-07-24T02:42:35.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2021-07-14T14:54:12.000Z (almost 5 years ago)
- Last Synced: 2025-06-25T06:44:19.999Z (about 1 year ago)
- Topics: conversion, hacktoberfest, iso639, language-codes, php
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 7
- Watchers: 3
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Language Codes Converter
========================
[](https://packagist.org/packages/leodido/langcode-conv) [](https://travis-ci.org/leodido/langcode-conv) [](https://coveralls.io/r/leodido/langcode-conv)
This library, based on [conversio library](https://github.com/leodido/conversio), is aimed to convert every existing language code to any format you want. No matter which format the input language code is.
Details
-------
The **available output formats** are:
1. `name`
The international (often english) name of the language
2. `native`
The language name written in native representation/s
3. `iso639-1`
The ISO 639-1 (two-letters code) language representation
4. `iso639-2/t`
The ISO 639-2/T (three-letters code for terminology applications) language representation
5. `iso639-2/b`
The ISO 639-2/B (three-letters code, for bibliographic applications) language representation
6. `iso639-3`
The ISO 639-3 (same as ISO 639-2/T except that for the macrolanguages) language representation
Currently **184 languages** are fully supported.
Examples
--------
First of all you need to create the conversion adapter and its options class.
```php
use Conversio\Conversion;
use Conversio\Adapter\LanguageCode;
use Conversio\Adapter\Options\LanguageCode;
// ...
$adapter = new LanguageCode();
$options = new LanguageCodeOptions();
```
Then, you can pass it to the `Conversion` class constructor (from [conversio library](https://github.com/leodido/conversio)):
```php
$converter = new Conversion($adapter);
$converter->setAdapterOptions($options);
```
Or, compactly:
```php
$converter = new Conversion(['adapter' => $adapter, 'options' => $options]);
```
Finally we need to specify the desired output format (see above the supported formats) of the conversion and perform it.
```php
$options->setOutput('native');
// ISO 639-1 => NATIVE
$converter->filter('it'); // italiano
```
Which ouputs, in this case `italiano`.
Have fun, try other language codes (e.g., `vie`, `tam`).
```php
// ISO 639-2/T => NATIVE
$converter->filter('vie'); // tiếng việt
$converter->filter('tam'); // தமிழ்
// ISO 639-3 => NATIVE
$converter->filter('yid + 2'); // ייִדיש
// ISO 639-3 => NAME
$options->setOutput('name');
$converter->filter('vie'); // vietnamese
$converter->filter('tam'); // tamil
$converter->filter('yid + 2'); // yiddish
```
Installation
------------
Add `leodido/langcode-conv` to your `composer.json`.
```json
{
"require": {
"leodido/langcode-conv": "v0.3.0"
}
}
```
References
----------
- Language codes and schemes [reference](http://en.wikipedia.org/wiki/Language_code)
- The [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) standard
- The [ISO 639-2](http://en.wikipedia.org/wiki/ISO_639-2) standard
- The [ISO 639-3](http://en.wikipedia.org/wiki/ISO_639-3) standard
- [List](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) of ISO 639-1 codes
- [List](http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes) of ISO 639-2 codes
- [List](http://en.wikipedia.org/wiki/List_of_ISO_639-3_codes) of ISO 639-3 codes
---
[](https://github.com/igrigorik/ga-beacon)