php - gettext,如何处理同音字?

标签 php gettext

使用获取文本

单值

echo gettext( "Hello, world!\n" );

复数

printf(ngettext("%d comment", "%d comments", $n), $n);

英文谐音?

echo gettext("Letter");// as in mail, for Russian outputs "письмо"
echo gettext("Letter");// as in character, for Russian outputs "буква" 

与英文单词“character”一样,它可以是一个人的性格,也可以是一个字母! gettext 应该如何识别同音异义词的正确翻译?

最佳答案

您正在寻找的是 gettext 的上下文,它可以解决您的示例中的歧义。您可以在 documentation 中找到有关信息.所需的方法 pgettext 仍未在 PHP 中实现,因此您可以使用 user comment 中所述的辅助方法。在 php 文档中。

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');

关于php - gettext,如何处理同音字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16260798/

相关文章:

php - 使用 php、ffmpeg 和 proc_open 逐帧读取视频

php - 我无法连接到mysql

php - 仅在 WooCommerce 中替换管理单个订单页面上的标题文本

javascript - 使用 gettext 翻译 .js 文件

c - 与 strftime 或 printf 相比,GNU gettext 的本地化行为不稳定

python - .po 文件中的 Django 生成的波兰语复数形式不起作用

php - 在 HTML 表中显示 MySQL 记录。什么失败了?

服务器上的 PHP 源代码安全

php - wkhtmltopdf - libfontconfig.so.1 : cannot open shared object file

java - 如何使用字段中的 linkText 提取 WebElements 并单击它