加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – gettext,如何处理同义词?

发布时间:2020-12-13 17:27:13 所属栏目:PHP教程 来源:网络整理
导读:使用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
使用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}04{$msgid}";
     $translation = dcgettext('messages',contextString,LC_MESSAGES);
     if ($translation == $contextString)  return $msgid;
     else  return $translation;
  }

}

在你的情况下会是

echo pgettext('mail','Letter');
echo pgettext('character','Letter');

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读