elaborate-code/php-json-tongue

一个用于从lang文件夹中的JSON文件加载本地化数据的门面

v1.2.1 2022-10-08 10:57 UTC

This package is auto-updated.

Last update: 2024-09-29 06:14:57 UTC


README

Packagist Version Packagist Downloads run-tests Test Coverage Fix PHP code style issues maintained

一个用于从JSON文件文件夹树加载本地化数据的门面。

开始使用

使用composer安装此包

composer require elaborate-code/php-json-tongue

要求

  • PHP 8.0或更高版本

用法

设置文件结构。

illustration

然后使用门面。

use ElaborateCode\JsonTongue\TongueFacade;

$tongue = new TongueFacade('/lang');

$localization = $tongue->transcribe();

$localization 将被设置如下

$localization = [
    "es" => [
        "programmer" => "programador",
        "interviewer" => "entrevistador",
        "Hello" => "Hola",
        "Good morning" => "buenos dias",
        //...
    ],
    "fr" => [
        "Hello" => "Salut",
        "Good morning" => "Bonjour",
        //...
    ]
    //...
];

测试

vendor/bin/pest

JSON Faker

就像测试Laravel应用时一样,我们临时填充数据库,并使用 RefreshDatabase 特性回滚数据库到初始状态。

此包包含 ElaborateCode\JsonTongue\JsonFaker\JsonFaker 类,它可以帮助创建一个临时的 locale文件夹JSON文件 树,这些文件包含翻译。

以下是一个示例

$json_faker = JsonFaker::make()
    ->addLocale('ar', [
        'ar.json' => [],
    ])
    ->addLocale('en', [
        'en.json' => [
            'en' => 'en',
            "I know. They're both good. It's hard to decide. McCain is older but he has more experience. Obama seems to have a lot of good ideas, but some people say he wants to raise taxes." => 'Lo sé. Ambos son buenos. Es difícil decidir. McCain es mayor pero tiene más experiencia. Obama parece tener muchas buenas ideas, pero algunas personas dicen que quiere aumentar los impuestos.',
        ],
        'one.json' => [
            'one' => 'one',
        ],
        'two.json' => [
            'two' => 'two',
        ],
    ])
    ->addLocale('multi', [
        'greetings.json' => [
            'en' => [
                'Hello' => 'Hello',
            ],
            'fr' => [
                'Hello' => 'Salut',
            ],
        ],
    ])
    ->write();

// Assert

$json_faker->rollback(); // Delete the complete file structure created for the test

此类可以帮助在贡献此包或使用此包时进行测试。

变更日志

贡献

有关详细信息,请参阅 CONTRIBUTING

许可证

MIT许可证(MIT)。有关更多信息,请参阅 许可证文件