【问题标题】:Internationalization - how to handle gender?国际化——如何处理性别问题?
【发布时间】:2015-05-11 23:41:48
【问题描述】:

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

我正在使用 cakephp 3 的内置工具来执行此操作。我的应用程序中有一句话必须用不同的英文翻译,无论用户是男人还是女人。在法语中,句子保持不变。

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

英文翻译:“xxx did not give him availability”代表男人,“xxx give her availability”代表女人。

起初,我的应用是这样的:

<?= __("{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。如何处理此类问题?

【问题讨论】:

    标签: cakephp internationalization cakephp-3.0


    【解决方案1】:

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

    问题在于 I18N shells 提取任务,它仅使用消息作为标识符来存储提取的值,导致之前的上下文被覆盖。我认为这是一个错误,请report it over at GitHub

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

    【讨论】:

    • 我是第一次使用 __x()。不知道我是在滥用它还是它是一个错误。感谢您的回答,我正在举报。
    猜你喜欢
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多