metarush/lang 问题修复 & 功能扩展

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

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

metarush/lang

最新稳定版本:v1.0.0

Composer 安装命令:

composer require metarush/lang

包简介

Language translations / i18n / l10n with replaceable variables.

README 文档

README

Language translations / i18n / l10n with replaceable variables.

Sometimes you don't need a full-blown translation package. If all you want is to read a language translation source (e.g., Yaml file) and optionally replace variables on it on runtime, then this package is for you.

Install

Install via composer as metarush/lang

Usage

  1. Create a language file e.g., en-US.yaml and store it in a folder of your choice e.g., locales/

  2. Put the ff. sample content in en-US.yaml:

foo: hello world
bar: the {{size}} {{color}} {{animal}} jumped

foo and bar will be the reference keys of each language string

  1. Put the ff. in your PHP code:
$lang = (new \MetaRush\Lang\Builder())
            ->setLocalePath('path/to/locales/folder/')
            ->setLocale('en-US')
            ->build();

$foo = $lang->get('foo');

// $foo now contains 'hello world'

To replace variables on runtime:

$vars = [
    'size'   => 'big',
    'color'  => 'brown',
    'animal' => 'fox',
];

$bar = $lang->get('bar', $vars);

// $bar now contains 'the big brown fox jumped'

Additional settings

->setOpenSyntax(string)

Change the open syntax of variables e.g., ->setOpenSyntax('%')

->setCloseSyntax(string)

Change the close syntax of variables e.g., ->setCloseSyntax('%')

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固