it-tem-papa / i18next-php
用于PHP的i18next JS库的端口
v3.0.0
2023-05-23 14:00 UTC
Requires
- php: >=8.0
- ext-json: *
- ext-mbstring: *
- psr/log: ^3.0
Requires (Dev)
- monolog/monolog: ^3.0
- phpunit/phpunit: 10.*
Suggests
- monolog/monolog: An excellent logging solution, integrates seamlessly
README
PHP版本的i18next。具有REST API。(即将推出 [tm])
本仓库中的代码主要基于JavaScript的原代码库,用PHP重写。本项目只关注i18next的最新版本,不考虑与之前版本的兼容性。
警告!
此版本可以使用,但可能包含错误。如果您发现任何问题,请报告或创建一个PR。
特性
- PSR3日志支持(psr/log是强制要求,但您不需要实际使用日志记录器)
- 与JS版本极为相似的API
- PHP特定的功能,如模块接口
- PHP 8.0+
- 自动语言检测支持
- JSON v4(必需)
用法
基本示例
// You can also use I18n globally via I18n::get() $i18n = new I18n([ 'lng' => 'en', 'resources' => [ 'en' => [ 'translation' => [ 'key' => 'Value', 'key_other ' => 'Value plural', 'deeper' => [ 'key' => 'Deep value' ] ] ] ] ]); $i18n->t('key'); // "Value" $i18n->t('key', ['count' => 5]); // "Value plural" $i18n->t('deeper.key'); // "Depp value"
Composer
简单地进入您的项目目录并运行
composer require it-tem-papa/i18next-php
待办事项
- 添加事件发射
Packagist
访问此页面 此处