承接 mateodioev/multi-lang 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mateodioev/multi-lang

最新稳定版本:v0.4.0

Composer 安装命令:

composer require mateodioev/multi-lang

包简介

A simple PHP class to manage multi-language websites.

README 文档

README

A simple package to manage multi-language in your project.

Installation

composer require mateodioev/multi-lang

Usage

  • Create a directory to save your language files, for example resources/lang.

  • Create a file for each language you want to support, for example en.json and es.json.

File en.json:

{
    "english_name": "English",
    "name": "English",
    "data": {
        "welcome": "Welcome {full_name} to our website",
        "goodbye": "Goodbye dear {full_name}"
    }
}

File es.json:

{
    "english_name": "Spanish",
    "name": "Español",
    "data": {
        "welcome": "Bienvenido {full_name} a nuestro sitio web",
        "goodbye": "Adiós querido {full_name}"
    }
}
  • Configure the dir
use Mateodioev\MultiLang\Cache\InMemoryCache;
use Mateodioev\MultiLang\Lang;

$config = \Mateodioev\MultiLang\Config::instance()
    ->withCache(new InMemoryCache()) // Optional;
Lang::setup(
    dir: __DIR__ . '/resources/lang',
    config: $config
);
  • Format the strings
// If the key does not exist it will return null
Lang::get('es')->data('welcome')?->format(['full_name' => 'Mateo']);
// Output: Bienvenido Mateo a nuestro sitio web

File format

  • english_name: The name of the language in English.
  • name: The name of the language in its own language.
  • data: The key-value pairs of the language strings.
    • key: The key of the string.
    • value: The value of the string. You can use placeholders to replace them with values.

WARNING: If the json file does not contain any of these keys or different data it will give an error.

Validate the files

You can validate the files to check if they have the correct format.

WARNING: Not use in production. This load and parse all the files

Lang::compareData();

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固