国际化——如何处理性别问题?

Internationalization - how to handle gender?

我有一个正在国际化的 cakephp 3 应用程序。该应用程序是用法语编写的,我正在添加英语。

我正在使用 cakephp 3 的内置工具来完成它。我的应用程序中有一句话,无论用户是男性还是女性,都必须以不同的方式翻译成英文。在法语中,句子保持不变。

法语句子:"xxx n'a pas indiqué ses disponibilités"

英文翻译:"xxx did not give his availabilities" 男性,"xxx give her availabilities" 女性。

起初,我的应用看起来像这样:

<?= __("{0} n'a pas indiqué ses disponibilités", $user->name); ?>

我修改了它以便提供两种不同的翻译:

<?php if ($user->gender == 'M'): ?>
<?= __("{0} n'a pas indiqué ses disponibilités", $user->name); ?>
<?php else: ?>
<?= __("{0} n'a pas indiqué ses disponibilités", $user->name); ?>
<?php endif; ?>

但是用bin/cake i18n extract生成pot文件的时候只提取了一句话。然后我尝试了这个:

<?php if ($user->gender == 'M'): ?>
<?= __x("speaking of a man", "{0} n'a pas indiqué ses disponibilités", $user->name); ?>
<?php else: ?>
<?= __x("speaking of a woman", "{0} n'a pas indiqué ses disponibilités", $user->name); ?>
<?php endif; ?>

仍然,pot文件中只记录了一个msgid。如何处理此类问题?

使用上下文翻译功能是正确的方法,你的最后一个例子是处理这种情况的正确方法。

问题出在I18N shells extract task,它只使用message作为identifier来存储提取的值,导致之前的context被覆盖。我认为这是一个错误,请 report it over at GitHub

在修复此问题之前,您必须手动将丢失的消息添加到您的 .pot 文件中。