Gettext与上下文一起使用(pgettext) [英] Gettext to work with context (pgettext)
本文介绍了Gettext与上下文一起使用(pgettext)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用pgettext来指定一些要翻译的字符串的上下文,我发现您需要自己在PHP中添加它,这就是我
I'd like to use pgettext to specify the context of some strings to translate, I've found that you need to add it yourself in PHP, which is what I did following this post's instructions. I've changed it a little bit to make it work (the dcgettext
function call had some errors):
function pgettext($context, $msgid) {
$contextString = "{$context}\004{$msgid}";
$translation = dcgettext('messages', $contextString, 5);
if ($translation == $contextString) return $msgid;
else return $translation;
}
但是此功能似乎不起作用,当我更改语言时,文本也没有更改.
But this function doesn't seems to work, the text is not changing when I change the language.
我想念什么?
推荐答案
我找到了一种对我有效的解决方案:
I've found a solution that is working well for me:
function pgettext($context, $msgid) {
$contextString = "{$context}\004{$msgid}";
$translation = _($contextString);
if($translation == $contextString) return $msgid;
else return $translation;
}
这篇关于Gettext与上下文一起使用(pgettext)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文