Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ddrv/php-translator
PHP library for localization application
https://github.com/ddrv/php-translator
i18n internationalization l10n localization php php-library translation
Last synced: 3 days ago
JSON representation
PHP library for localization application
- Host: GitHub
- URL: https://github.com/ddrv/php-translator
- Owner: ddrv
- License: mit
- Created: 2020-05-02T14:47:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-04T12:05:18.000Z (over 4 years ago)
- Last Synced: 2024-08-27T15:43:02.971Z (3 months ago)
- Topics: i18n, internationalization, l10n, localization, php, php-library, translation
- Language: PHP
- Homepage: https://packagist.org/packages/ddrv/translator
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ddrv/translator
[![Latest Stable Version](https://img.shields.io/packagist/v/ddrv/translator.svg?style=flat-square)](https://packagist.org/packages/ddrv/translator)
[![Total Downloads](https://img.shields.io/packagist/dt/ddrv/translator.svg?style=flat-square)](https://packagist.org/packages/ddrv/translator/stats)
[![License](https://img.shields.io/packagist/l/ddrv/translator.svg?style=flat-square)](https://github.com/ddrv/php-translator/blob/master/LICENSE)
[![PHP](https://img.shields.io/packagist/php-v/ddrv/translator.svg?style=flat-square)](https://php.net)PHP library for localization application.
# Install
1. Run in terminal:
```text
composer require ddrv/translator:^2
```1. Include autoload file
```php
require_once 'vendor/autoload.php';
```# Usage
1. Prepare translations
```php
'It is test!',
'hello' => 'Hello, %name%',
'count' => '%count% element|%count% elements|{0}no elements',
'interval' => '[-Inf,0[negative|[0,Inf]positive',
'multi' => [
'level' => [
'key' => 'It is key in multilevel array.',
],
],
];
``````php
'Это тест!',
'hello' => 'Привет, %name%',
'count' => '%count% элемент|%count% элемента|%count% элементов|{0}элементов нет',
'interval' => '[-Inf,0[отрицательное|[0,Inf]положительное',
'multi' => [
'level' => [
'key' => 'Это ключ в многоуровневом массиве.',
],
],
];
```1. Init library
```php
trans('default:test'); // It is test!
$translator->trans('default:multi.level.key'); // It is key in multilevel array.
$translator->trans('default:test', [], 'ru_RU'); // Это тест!$translator->setLocale('ru_RU');
$translator->trans('default:test'); // Это тест!
$translator->trans('default:multi.level.key'); // Это ключ в многоуровневом массиве.
```1. Parameters
```php
trans('default:hello', ['name' => 'Ivan']); // Hello, Ivan!
$translator->trans('default:hello', ['name' => 'John']); // Hello, John!
```1. Pluralization
```php
trans('default:count', ['count' => 1]); // 1 element!
$translator->trans('default:count', ['count' => 2]); // 2 elements!$translator->trans('default:interval', ['count' => -2]); // negative
$translator->trans('default:interval', ['count' => 2]); // positive
```You can develop your loader that implements the `\Ddrv\Translator\Contract\DomainLoader` interface.
You can use multiple loaders at once
```php
addLoader($loader2);
$loader->addLoader($loader3);$translations = new TranslationProvider($loader);
$translator = new Translator('en_US', $translations);
```You may wrap your loader to `\Ddrv\Translator\Loader\CachedLoader`
```php