我添加了一个用于gettext转换的库。添加了相应的po和mo文件。
翻译工作正常。
现在当我更新我的po文件时,更改一些翻译..之后当我重新加载页面时,我得到的是旧翻译,而不是新翻译。
这是图书馆代码:
/**
* This method overides the original load method. Its duty is loading the domain files by config or by default internal settings.
*
*/
function load_gettext($userlang = false) {
/* I want the super object */
if ($userlang)
$this->gettext_language = $userlang;
else
$this->gettext_language = 'it_IT';
log_message('debug', 'Gettext Class gettext_language was set by parameter:' . $this->gettext_language);
putenv("LANG=$this->gettext_language");
setlocale(LC_ALL, $this->gettext_language);
/* Let's set the path of .po files */
$this->gettext_path = APPPATH . 'language/locale';
log_message('debug', 'Gettext Class path chosen is: ' . $this->gettext_path);
bindtextdomain($this->gettext_domain, $this->gettext_path);
textdomain($this->gettext_domain);
log_message('debug', 'Gettext Class the domain chosen is: ' . $this->gettext_domain);
return true;
}
/**
* Plural forms added by Tchinkatchuk
* http://www.codeigniter.com/forums/viewthread/2168/
*/
/**
* The translator method
*
* @param string $original the original string to translate
* @param array $aParams the plural parameters
* @return the string translated
*/
function _trans($original, $aParams = false) {
if (isset($aParams['plural']) && isset($aParams['count'])) {
$sTranslate = ngettext($original, $aParams['plural'], $aParams['count']);
$sTranslate = $this->replaceDynamically($sTranslate, $aParams);
} else {
$sTranslate = gettext($original);
if (is_array($aParams) && count($aParams))
$sTranslate = $this->replaceDynamically($sTranslate, $aParams);
}
return $sTranslate;
}
这是控制器中的用法:
$this->pos_language->load_gettext('fr_FR');
echo $this->pos_language->_trans('Hello world, good morning');
答案 0 :(得分:1)
我认为您需要将.po文件编译为.mo文件。 Gettext使用.mo文件,.po只是一种人类可读的形式。
如果你还没有完成编译步骤,你的应用程序仍在阅读旧的.mo文件,其中包含未翻译的字符串......
此页面提供了有关gettext翻译的更多信息:http://wiki.creativecommons.org/Translating_PO_Files
答案 1 :(得分:0)
我写了一个帮助器,将php-gettext与Smarty&代码点火器2 http://bit.ly/rrITVx
我希望它可以提供帮助