elaborate-code/php-json-tongue 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

elaborate-code/php-json-tongue

Composer 安装命令:

composer require elaborate-code/php-json-tongue

包简介

A Facade for loading localization data from JSONs within a lang folder

README 文档

README

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

A Façade for loading localization data from a folder tree of JSON files.

Get started

Install the package with composer:

composer require elaborate-code/php-json-tongue

Requirements:

  • PHP 8.0 or higher

Usage

Set the file structure.

illustration

Then use the facade.

use ElaborateCode\JsonTongue\TongueFacade;

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

$localization = $tongue->transcribe();

$localization will be set like:

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

Testing

vendor/bin/pest

JSON Faker

Just like when testing Laravel apps, we populate the database temporarily and use the RefreshDatabase trait to rollback the database to its fresh state.

This package ships with ElaborateCode\JsonTongue\JsonFaker\JsonFaker class that helps create a temporary tree of locale folders and JSON files filled with translations.

Here is an example:

$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

This class can help make tests when contributing on this package or when using this package.

Changelog

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 2.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固