Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rancoud/i18n
Internationalization Package
https://github.com/rancoud/i18n
composer coverage i18n packagist php php74 phpunit phpunit9
Last synced: about 1 month ago
JSON representation
Internationalization Package
- Host: GitHub
- URL: https://github.com/rancoud/i18n
- Owner: rancoud
- License: mit
- Created: 2018-10-22T06:45:37.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-27T00:34:32.000Z (over 4 years ago)
- Last Synced: 2024-11-29T14:56:05.009Z (about 1 month ago)
- Topics: composer, coverage, i18n, packagist, php, php74, phpunit, phpunit9
- Language: PHP
- Homepage: https://packagist.org/packages/rancoud/i18n
- Size: 29.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# I18N Package
![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/rancoud/i18n)
[![Packagist Version](https://img.shields.io/packagist/v/rancoud/i18n)](https://packagist.org/packages/rancoud/i18n)
[![Packagist Downloads](https://img.shields.io/packagist/dt/rancoud/i18n)](https://packagist.org/packages/rancoud/i18n)
[![Composer dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://github.com/rancoud/i18n/blob/master/composer.json)
[![Test workflow](https://img.shields.io/github/workflow/status/rancoud/i18n/test?label=test&logo=github)](https://github.com/rancoud/i18n/actions?workflow=test)
[![Codecov](https://img.shields.io/codecov/c/github/rancoud/i18n?logo=codecov)](https://codecov.io/gh/rancoud/i18n)
[![composer.lock](https://poser.pugx.org/rancoud/i18n/composerlock)](https://packagist.org/packages/rancoud/i18n)I18N.
## Installation
```php
composer require rancoud/i18n
```## How to use it?
You need a file `LANG.php` where LANG is the filename.
It will contains an array key values:
```php
return [
'Hello' => 'Bonjour'
];
```
You have to set the default directory and language
```php
$defaultDirectory = '/path/to/translations/';
$defaultLanguage = 'en';
I18N::setDefaults($directory, $defaultLanguage);
```
In action:
```php
I18N::echo('Hello');
// it will produce in output 'Hello'I18N::echo('another string');
// it will produce in output 'another string' because the key doesn't exist in the file$string = I18N::get('Hello');
// it will return 'Hello'// you can use different language file instead of the default one
$string = I18N::get('string in other lang', 'es');
// it will return the translation of 'string in other lang' present in the es.php file
```## I18N Methods
### General static Commands
* setDefaults(directory: string, language: string):void
* echo(key: string, [language: string = null]):void
* get(key: string, [language: string = null]):string## How to Dev
`composer ci` for php-cs-fixer and phpunit and coverage
`composer lint` for php-cs-fixer
`composer test` for phpunit and coverage