eden/language

Eden语言组件。

4.0.1 2015-10-13 05:03 UTC

This package is auto-updated.

Last update: 2024-09-13 20:25:30 UTC


README

Build Status

====

安装

composer install eden/language

====

简介

Eden中的语言功能强大,定义简单,旨在与谷歌翻译等翻译服务协同工作。以下图示展示了如何设置法语翻译器。

图1. 法语翻译器

//initial translations
$translations = array(
	'Hello'         => 'Bonjour',
	'How are you?'  => 'Como tale vous?');
 
//load up the translation   
$french = eden('language', $translations);
 
//you can add translations on the fly
$french->translate('I am good thank you, and you?', 'Bien mercy, et vous?');
 
//now echo some translations
echo $french->get('Hello'); //--> Bonjour
echo $french->get('How are you?'); //--> Como tale vous?
echo $french->get('I am good thank you, and you?'); //--> Bien mercy, et vous?

为了方便使用,我们还使语言对象可以作为数组访问。下一图与图1相同,只是它使用数组来操作对象。

图2. 语言作为数组

//initial translations
$translations = array(
	'Hello'         => 'Bonjour',
	'How are you?'  => 'Como tale vous?');
 
//load up the translation   
$french = eden('language', $translations);
 
//you can add translations on the fly
$french['I am good thank you, and you?] = 'Bien mercy, et vous?';
 
//now echo some translations
echo $french['Hello']; //--> Bonjour
echo $french['How are you?']; //--> Como tale vous?
echo $french['I am good thank you, and you?']; //--> Bien mercy, et vous?
 
foreach($french as $default => $translation) {
	echo $translation;
}

通常,使用语言的网站通常从加载和保存翻译文件开始和结束。通过在页面生命周期中通过Eden语言对象和后续保存,始终保持语言文件始终是最新的。

注意:Eden本身并不进行实际的翻译。一旦文件生成并保存,您应该通过翻译服务运行它。

图3. 加载和保存语言文件

//load up a translation file
$translations = eden('file', '/path/to/french.php')->getData();
$french = eden('language', $translations);
 
//add to translation
$french['I am good thank you, and you?] = 'Bien mercy, et vous?';
 
//save back to file
$french->save('/path/to/french.php');

====

API

====

获取

返回翻译键。如果键未设置,则将键设置为键的值

用法

eden('language')->get(string );

参数

  • 字符串

返回 string

示例

eden('language')->get();

====

getLanguage

返回语言设置

用法

eden('language')->getLanguage();

参数

返回 array

====

保存

将语言保存到文件

用法

eden('language')->save(string|null $file);

参数

  • string|null $file - 要保存的文件

返回 this

示例

eden('language')->save();

====

翻译

将翻译值设置为指定的键

用法

eden('language')->translate(*string $key, *string $value);

参数

  • *string $key - 翻译键
  • *string $value - 如果找不到翻译,将键设置为默认值

返回 this

示例

eden('language')->translate('foo', 'foo');

====

#对Eden的贡献

对Eden的贡献遵循GitHub工作流程。在贡献之前,请仔细阅读。

##使用Eden仓库和您的分支设置您的机器

  1. 分支仓库
  2. 在本地终端启动,从您的分支的v4分支创建一个新分支,分支名称描述了您的更改。可能的分支名称类型
    • bugfix
    • feature
    • improvement
  3. 进行更改。始终确保在所有提交上签名(git commit -s -m "提交信息")

##制作拉取请求

  1. 请在提交拉取请求之前确保运行phpunit
  2. 将您的代码推送到您的远程分支版本。
  3. 回到GitHub上的您的分支版本,提交拉取请求。
  4. Eden开发者将审查您的代码,并在它被认为适合时将其合并。