romeoz / rock-i18n
PHP的i18n库
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-09-24 02:49:21 UTC
README
功能
- 适用于Rock框架的独立模块/组件
安装
从命令行
composer require romeoz/rock-i18n
在你的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)
添加数组形式的i18-记录列表。
use rock\i18n\i18n; $i18n = new i18n; $i18n->addMulti([ 'en' => [ // locale 'lang' => [ // category 'hello' => 'Hello world!' ] ], 'ru' => [ 'lang' => [ 'hello' => 'Привет мир!' ] ] ]);
####addDicts(array $dicts)
通过路径添加字典。
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
可以是字符串、复合字符串(months.nov
)或数组(['months', 'nov']
)。
$i18n->translate('hello');
###static t(string|array$keys, array $placeholders = [], $category = null, $locale = null)
通过静态方法进行翻译。
i18n::t('hello');
###locale(string $locale)
选择地区。
use rock\i18n\i18n; $i18n = new i18n; $i18n->locale('fr'); $i18n->translate('hello');
###category($category)
选择类别。
use rock\i18n\i18n; $i18n = new i18n; $i18n->locale('fr')->category('validate'); $i18n->translate('required');
要求
- PHP 5.4+
许可证
Rock i18n库是开源软件,许可协议为MIT许可证。