定制 nabeghe/light-localization 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nabeghe/light-localization

最新稳定版本:v1.1.3

Composer 安装命令:

composer require nabeghe/light-localization

包简介

A light weight, key-value & path-based PHP localization library that translations are loaded up when needed.

README 文档

README

A light weight, key-value & path-based PHP localization library that translations are loaded up when needed.

🫡 Usage

🚀 Installation

You can install the package via composer:

composer require nabeghe/light-localization

📁 Localization Directory

  • Create a directory for localization.
  • In this directory, create new folders, each of these folders actually represent localization codes. They can be language codes or anything else.
  • Inside each code directory, php files will be placed, each of these files has the role of a translator.
    • These files can return an array or an object that inheritance from Nabeghe\LightLocalization\Translator class.
    • If it's an array, each key is a translation key & it will represent a value, but if it's an object, each field or method is a translation key. The priority is with the method & it must return a value.
    • Objects can implement the ArrayAccess interface in addition to inheriting from the mentioned class.
use Nabeghe\LightLocalization\Localizer;

/*
 * Example of Translations Directory:
 | /langs/
 |      /en/
 |          main.php
 |          messages.php
 |      /fa/
 |          main.php
 |          messages.php
 */

$defaultLocalizer = new Localizer(__DIR__.'/langs', 'en');
$localizer = new Localizer(__DIR__.'/langs', 'fa', $defaultLocalizer);

// value of `title` key, from `main.php` translation file (default value for second argument).
echo $localizer->get('title');

// value of `hello` key, from `messages.php` translation file.
echo $localizer->get('hello', 'messages');

Notice: The localization code can be specified in the constructor method. Of course, it's possible to change it later via method setCode.

Notice: For each localizer, a default localizer can be specified in the constructor. Additionally, instead of specifying a default localizer, a string can be designated as the default translation.

🧩 Features

  • Get the value (translation) using the key.
  • Fetch random translations from keys with array of strings using the rnd method instead of get.
  • Localization code (the second parameter of Localizer constructor).
  • Default translation that can be a string or another localizer. (the third parameter of Localizer constructor).
  • Create different translators in different files and array-based or class-based translations.
  • Dynamic translations.
  • Reload the translator.
  • Remove the loaded translator.
  • Refreshing translators and reloading them.
  • Changing the localization code.

📖 License

Licensed under the MIT license, see LICENSE.md for details.

统计信息

  • 总下载量: 93
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-19