Translations: Español
PHP library to get language name from code.
- Requirements
- Installation
- Available Classes
- Usage
- List in JSON format
- Tests
- TODO
- Changelog
- Contribution
- Sponsor
- License
Operating System: Linux | Windows.
PHP versions: 8.0 | 8.1 | 8.2.
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
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;
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
Example of use for this library:
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)',
(...)
]
use Josantonius\LanguageCode\LanguageCode;
$languageCode = new LanguageCode();
$languageCode->getCode('Spanish'); // es
use Josantonius\LanguageCode\LanguageCodeCollection;
LanguageCodeCollection::getCode('Turkish'); // tr
use Josantonius\LanguageCode\LanguageCode;
$languageCode = new LanguageCode();
$languageCode->getName('eo'); // Esperanto
use Josantonius\LanguageCode\LanguageCodeCollection;
LanguageCodeCollection::getName('de'); // German
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
- 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)
Detailed changes for each release are documented in the release notes.
Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue.
Thanks to all contributors! ❤️
If this project helps you to reduce your development time, you can sponsor me to support my open source work 😊
This repository is licensed under the MIT License.
Copyright © 2017-present, Josantonius