- Standalone module/component for Rock Framework
From the Command Line:
composer require romeoz/rock-i18n
In your composer.json:
{
"require": {
"romeoz/rock-i18n": "*"
}
}
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!
####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');
- PHP 5.4+
Rock i18n library is open-sourced software licensed under the MIT license.