GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - josantonius/php-language-code: PHP library to get language name from language code

BranchesTags
Open more actions menu

Latest commit

 

History

41 Commits
41 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
src
src
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpcs.xml
phpcs.xml
 
 
phpmd.xml
phpmd.xml
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

PHP LanguageCode library

Latest Stable Version License Total Downloads CI CodeCov PSR1 PSR4 PSR12

Translations: Español

PHP library to get language name from code.


  • Requirements
  • Installation
  • Available Classes
    • LanguageCode Class
    • LanguageCodeCollection Class
  • Usage
  • List in JSON format
  • Tests
  • TODO
  • Changelog
  • Contribution
  • Sponsor
  • License

Requirements

Operating System: Linux | Windows.

PHP versions: 8.0 | 8.1 | 8.2.

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 Classes

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

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

Example of use for this library:

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

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

use Josantonius\LanguageCode\LanguageCode;

$languageCode = new LanguageCode();

$languageCode->getName('eo'); // Esperanto
use Josantonius\LanguageCode\LanguageCodeCollection;

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

About

PHP library to get language name from language code

josantonius.dev

Topics

composeriso639-1language-codelanguage-codesphp

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity

Stars

5 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.