首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >参数2的格式规范(如“msgstr[0]”中的)在“msgid_plural”中不存在

参数2的格式规范(如“msgstr[0]”中的)在“msgid_plural”中不存在
EN

Stack Overflow用户
提问于 2014-11-19 15:47:32
回答 1查看 2.4K关注 0票数 0

我有以下代码:

代码语言:javascript
复制
public function bulk_updated_messages ( $bulk_messages = array(), $bulk_counts = array() ) {

    $bulk_messages[ $this->post_type ] = array(
        'updated'   => sprintf( _n( '%1$s %2$s updated.', '%1$s %3$s updated.', $bulk_counts['updated'], 'yosilose' ), $bulk_counts['updated'], $this->single, $this->plural ),
        'locked'    => sprintf( _n( '%1$s %2$s not updated, somebody is editing it.', '%1$s %3$s not updated, somebody is editing them.', $bulk_counts['locked'], 'yosilose' ), $bulk_counts['locked'], $this->single, $this->plural ),
        'deleted'   => sprintf( _n( '%1$s %2$s permanently deleted.', '%1$s %3$s permanently deleted.', $bulk_counts['deleted'], 'yosilose' ), $bulk_counts['deleted'], $this->single, $this->plural ),
        'trashed'   => sprintf( _n( '%1$s %2$s moved to the Trash.', '%1$s %3$s moved to the Trash.', $bulk_counts['trashed'], 'yosilose' ), $bulk_counts['trashed'], $this->single, $this->plural ),
        'untrashed' => sprintf( _n( '%1$s %2$s restored from the Trash.', '%1$s %3$s restored from the Trash.', $bulk_counts['untrashed'], 'yosilose' ), $bulk_counts['untrashed'], $this->single, $this->plural ),
    );

    return $bulk_messages;
}

然后在我的.po文件中有:

代码语言:javascript
复制
#, php-format
msgid "%1$s %2$s updated."
msgid_plural "%1$s %3$s updated."
msgstr[0] "%1$s %2$s actualizado/a."
msgstr[1] "%1$s %3$s actualizados/as."

但是,当我尝试用Poedit创建我的.mo文件时,我得到了以下错误:

代码语言:javascript
复制
a format specification for argument 2, as in 'msgstr[0]', doesn't exist in 'msgid_plural'

我不明白这里出了什么问题。这是我称之为"_n“的方式,还是我翻译的字符串中的什么东西?

我知道这和斯普林特的位置标志有关.显然,我不喜欢msgid_plurals的3%,而不是msgid.但不应该仅仅翻译字符串“原样”吗?我将在运行时将翻译的字符串传递给sprintf,插入适当的名词.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-20 09:32:15

这并不是Poedit不喜欢它,而是gettext msgfmt工具--而且您的多义性检查方法失败了。正如您所观察到的,原因是您必须在msgidmsgid_plural中使用相同的参数。就这么做。

如果您想知道为什么,这是因为您的代码忽略了某些语言可能有更多(或更少!)不只是两种形式,单数和复数。斯拉夫语有3种,阿拉伯语有6种,日语只有1种。

就像通常的情况一样,gettext手册详细讨论了这个问题:node/Plural-forms.html

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27021037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档