exactcure/i18next-php

将i18next JS库移植到PHP

安装数: 18,094

依赖者: 0

建议者: 0

安全: 0

星星: 0

观察者: 0

分支: 3

开放问题: 0

类型:项目

v2.0.1 2023-05-31 15:14 UTC

This package is auto-updated.

Last update: 2024-08-30 01:32:23 UTC


README

PHP中的i18next的移植。带有REST API。(即将推出 [tm])

此存储库中的代码主要基于JavaScript原始代码库,用PHP重写。本项目只关注i18next的最新版本,不考虑与旧版本的兼容性。

警告!

此版本可以使用,但可能包含错误。如果您发现任何问题,请报告它们或创建PR。

特性

  • PSR3日志支持(psr/log是硬性要求,但您不需要实际使用日志记录器)
  • 与JS版本具有非常相似的API
  • PHP特定特性,如模块接口
  • PHP 8.0+
  • 自动语言检测支持

用法

在此查看所有示例

基本示例

// You can also use I18n globally via I18n::get()

$i18n = new I18n([
    'lng'           =>  'en',
    'resources'     =>  [
        'en'        =>  [
            'translation'       =>  [
                'key'           =>  'Value',
                'key_plural'    =>  '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 exactcure/i18next-php

待办事项

  • 添加事件发射

Packagist

访问页面此处