romeoz / rock-i18n
i18n library for PHP
0.11.0
2015-11-07 01:31 UTC
Requires
- php: >=5.4.0
- romeoz/rock-base: 0.12.*
Requires (Dev)
- phpunit/phpunit: ^4.7.0
This package is not auto-updated.
Last update: 2024-11-05 03:29:00 UTC
README
Features
- Standalone module/component for Rock Framework
Installation
From the Command Line:
composer require romeoz/rock-i18n
In your composer.json:
{ "require": { "romeoz/rock-i18n": "*" } }
Quick Start
use rock\i18n\i18n; $i18n = new i18n; $i18n->add('hello', 'Hello {{placeholder}}'); $i18n->translate('hello', ['placeholder' => 'world!']); // output: Hello world! // or i18n::t('hello', ['placeholder' => 'Rock!']); // output: Hello Rock!
Documentation
####addMulti(array $data)
Adds list i18-records as array.
use rock\i18n\i18n; $i18n = new i18n; $i18n->addMulti([ 'en' => [ // locale 'lang' => [ // category 'hello' => 'Hello world!' ] ], 'ru' => [ 'lang' => [ 'hello' => 'Привет мир!' ] ] ]);
####addDicts(array $dicts)
Adds dicts as paths.
use rock\i18n\i18n; $config = [ 'pathDicts' => [ 'en' => [ 'path/to/en/lang.php', 'path/to/en/validate.php', ] ] ] ]; $i18n = new i18n($config); // or $paths = [ 'en' => [ 'path/to/en/lang.php', 'path/to/en/validate.php', ] ]; $i18n->addDicts($paths);
###translate(string|array $keys, array $placeholders = [])
$keys
can be a string, composite string (months.nov
), or array (['months', 'nov']
).
$i18n->translate('hello');
###static t(string|array$keys, array $placeholders = [], $category = null, $locale = null)
Translation via the static method.
i18n::t('hello');
###locale(string $locale)
Select locale.
use rock\i18n\i18n; $i18n = new i18n; $i18n->locale('fr'); $i18n->translate('hello');
###category($category)
Select category.
use rock\i18n\i18n; $i18n = new i18n; $i18n->locale('fr')->category('validate'); $i18n->translate('required');
Requirements
- PHP 5.4+
License
Rock i18n library is open-sourced software licensed under the MIT license.