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 许可。