josantonius/languagecode

This package is abandoned and no longer maintained. The author suggests using the josantonius/language-code package instead.

PHP library to get language name from code.

Fund package maintenance!
Josantonius

v2.0.0 2022-08-02 01:33 UTC

This package is auto-updated.

Last update: 2022-08-02 01:35:56 UTC


README

Latest Stable Version License Total Downloads CI CodeCov PSR1 PSR4 PSR12

Translations: Español

PHP library to get language name from code.

Requirements

This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.

Installation

The preferred way to install this extension is through Composer.

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 Methods

Available methods in this library:

Get all language codes as array

$languageCode->all(): array

Get language code from language name

$languageCode->getCode(string $languageName): string|null

Get language name from language code

$languageCode->getName(string $languageCode): string|null

Quick Start

To use this library:

Using Objects

use Josantonius\LanguageCode\LanguageCode;

$languageCode = new LanguageCode();

Using Static Collection

Alternatively you can use the collection to access the methods statically:

use Josantonius\LanguageCode\LanguageCodeCollection;

Usage

Example of use for this library:

- Get all language codes as array

Using objects:

$languageCode->all();

Using the static collection:

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

Using objects:

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

Using the static collection:

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

- Get language name from language code

Using objects:

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

Using the static collection:

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

List in JSON format

Go to the resource.

Tests

To run tests you just need composer 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:

composer phpunit

Run code standard tests with PHPCS:

composer phpcs

Run PHP Mess Detector tests to detect inconsistencies in code style:

composer phpmd

Run all previous tests:

composer tests

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

Detailed changes for each release are documented in the release notes.

Contribution

Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue.

Thanks to all contributors! ❤️

Sponsor

If this project helps you to reduce your development time, you can sponsor me to support my open source work 😊

License

This repository is licensed under the MIT License.

Copyright © 2017-present, Josantonius