定制 technicalguru/i18n 二次开发

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

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

technicalguru/i18n

最新稳定版本:v1.0.6

Composer 安装命令:

composer require technicalguru/i18n

包简介

Provides localization features for PHP apps

README 文档

README

Provides localization features for PHP apps. It reads a local i18n file for your application and provides localized values for keys.

License

This project is licensed under GNU LGPL 3.0.

Installation

By Composer

composer install technicalguru/i18n

By Package Download

You can download the source code packages from GitHub Release Page

How to use

Create a localization file

Create a file i18n.php somewhere where it can be accessed from your application.

<?php

/** Put here your language translations */
return array(
	'welcome' => array(
		'de' => 'Willkommen!',
		'en' => 'Welcome!',
	),
);

Initialize I18N

Tell I18N where it will find your localizations and what your default language is.

use TgI18n\I18n;

I18N::$i18nFile        = '/my/path/to/i18n.php';
I18N::$defaultLangCode = 'de';

Default Initialization

You don't need to tell I18N where to find your localizations when they exists in one of these places. The file needs to be named i18n.php.

  • Web Context Document Root as defined by $_SERVER['CONTEXT_DOCUMENT_ROOT']
  • Web Document Root as defined by $_SERVER['DOCUMENT_ROOT']
  • Current directory of your running script file (that is the one being executed)

You don't need to initialize the default language code, when it is en.

Translating Values

Now you are setup to use your localizations:

use TgI18n\I18n;

echo I18N::_('welcome');
echo I18N::_('welcome', 'en');
echo I18N::_('welcome', 'de');

The _($key) static method always returns a value. If the given key cannot be found then the key itself will be returned.

If you prefer to have NULL returned, then use __($key):

use TgI18n\I18n;

echo I18N::__('welcome');
echo I18N::__('welcome', 'en');
echo I18N::__('welcome', 'de');

Contribution

Report a bug, request an enhancement or pull request at the GitHub Issue Tracker.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2020-11-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固