使用gettext
单值
echo gettext( "Hello,world!\n" );
复数
printf(ngettext("%d comment","%d comments",$n),$n);
英文homonym?
echo gettext("Letter");// as in mail,for Russian outputs "письмо"
echo gettext("Letter");// as in character,for Russian outputs "буква"
与英文单词“character”相同,可以是一个人或一个字母的字符!
gettext应该如何识别同义词的正确翻译?
您正在寻找的是gettext的上下文,可以解决像您的示例这样的歧义.您可以在
documentation中找到有关信息.仍然需要的方法pgettext不在PHP中实现,因此您可以使用PHP文档中的
user comment中所述的帮助方法.
if (!function_exists('pgettext')) {
function pgettext($context,$msgid)
{
$contextString = "{$context}\004{$msgid}";
$translation = dcgettext('messages',contextString,LC_MESSAGES);
if ($translation == $contextString) return $msgid;
else return $translation;
}
}
在你的情况下会是
echo pgettext('mail','Letter');
echo pgettext('character','Letter');