GithubHelp home page GithubHelp logo

langcode-conv's Introduction

Language Codes Converter

Latest Stable Version Build Status Coverage

This library, based on conversio library, 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.

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):

$converter = new Conversion($adapter);
$converter->setAdapterOptions($options);

Or, compactly:

$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.

$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).

// 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.

{
   "require": {
       "leodido/langcode-conv": "v0.3.0"
   }
}

References


Analytics

langcode-conv's People

Contributors

blackbitdevs avatar leodido avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

langcode-conv's Issues

Enable multiple values

The name and native fields can contains multiple values.
See here, and here for example.

Ensure that this works.

$adapter = new LanguageCode();
$options = new LanguageCodeOptions();
$converter = new Conversion(['adapter' => $adapter, 'options' => $options]);
$options->setOutput('iso639-1');
// NATIVE => ISO 639-1
$converter->filter('valencian'); // ca

End user should not be forced to do.

// ...
$converter->filter('catalan, valencian'); // ca

Handle comma separated values (or convert the array).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.