参数2的格式规范,如'msgstr [0]','msgid_plural'中不存在

时间:2014-11-19 15:47:33

标签: wordpress internationalization translation poedit

我有以下代码:

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文件中我有:

#, 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文件时,我收到了这个错误:

a format specification for argument 2, as in 'msgstr[0]', doesn't exist in 'msgid_plural'

我不知道这里有什么问题。这是我打电话" _n"或我翻译的字符串中的某些内容?

我看到这与sprintf位置标记有某种关系...... poedit显然不喜欢我在msgid_plurals中有$ 3%s而不是msgid ...但是不应该只是翻译字符串"原样"?我会在运行时将已翻译的字符串传递给sprintf,并将适当的名词插入到位...

1 个答案:

答案 0 :(得分:2)

Poedit并不喜欢它,它是gettext msgfmt工具 - 你做复数形式的方式未能通过它的理智检查。正如您所观察到的,原因是您必须在msgidmsgid_plural中使用相同的参数。就这么做。

如果你想知道为什么,那是因为你的代码忽略了某些语言可能比两种形式(单数和复数)更多(或更少)的可能性。斯拉夫语有3种,阿拉伯语有6种,日语只有1种。你的代码永远无法使用这些语言。

通常情况下,GNU gettext手册会详细讨论这个问题: http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Plural-forms.html