定制 gelembjuk/locale 二次开发

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

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

gelembjuk/locale

最新稳定版本:2.0.2

Composer 安装命令:

composer require gelembjuk/locale

包简介

Internationalization support for PHP applications. It is a simple set of classes to manage languages/locales, to translate texts depending on a locale. The package contains a trait to include internationalization functions to any classes very easy and with minimum coding.

README 文档

README

Internationalization support for PHP applications. It is a simple set of classes to manage languages/locales, to translate texts depending on a locale. The package contains a trait to include internationalization functions to any classes very easy and with minimum coding.

Installation

Using composer: gelembjuk/locale require: {"gelembjuk/locale": "1.*"}

Configuration

No configuration needed.

You need to have a folder with your texts on different languages. Separate fodler for each locale, like en,ge,it,.... Each folder should contain minimum one file default.txt

Translation files have simple key=values format

Usage

require '../vendor/autoload.php';

$translation = new Gelembjuk\Locale\Translate(
	array(
		'localespath' => $lang_folder_path, // path to your translations directory
		'locale' => $locale // current locale, 2 symbol language code
	)
	);
	
echo $translation->getText('hello',''/*default group*/,$username);  // hello = Hello, %s on our site. $username will be put in place of %s

echo $translation->getText('welcome');

echo $translation->getText('backsoon','logoutpage'); // custom texts group in a separate web site

Trait usage

class MyClass {
	// include translation functions
	use Gelembjuk\Locale\GetTextTrait;
	
	public function doSomething() {
		echo $this->getText('welcome').'<br>';
	}
	
	public function andAgainWelcome($name) {
		// use short call for getText
		echo $this->_('hello','',$name).'<br>';
	}
}

$obj = new MyClass();

$obj->setTranslation($translation);

$obj->doSomething();

$obj->andAgainWelcome($username);

$obj->setLocale('en');

$obj->andAgainWelcome($username);

Languages manager usage

$langobj = new Gelembjuk\Locale\Languages(array('localespath' => $lang_folder_path));

// list of used languages, used are languages with a folder in $lang_folder_path
$languages = $langobj->getUsedLanguages();

// print language select form

echo '<form name=\'langform\' method=\'GET\' action="index.php">';

echo $langobj->getHTMLSelect(' name="locale" onchange="document.langform.submit()" ',$locale/*current selected locale*/);

echo '</form>';

Author

Roman Gelembjuk (@gelembjuk)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-31