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

I have the following code:

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;
}

And then in my .po file I have:

Read More
#, 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."

But when I try to create my .mo file with Poedit, I get this error:

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

I don’t get what’s wrong here. Is it the way I call “_n”, or something in my translated string?

I see that is somehow related to the sprintf position markers… that poedit apparently doesn’t like that I have $3%s in msgid_plurals and not in msgid… but shouldn’t just translate the string “as is”? I’ll pass the translated strings to sprintf at runtime, inserting the appropriate nouns in place…

Related posts

Leave a Reply

1 comment

  1. It’s not that Poedit doesn’t like it, it’s gettext msgfmt tool — and your way of doing plurals fails its sanity checks. As you observed, the reason is that you must use the same arguments in both msgid and msgid_plural. Just do it.

    If you’re wondering why, it’s because your code ignores the possibility that some languages may have more (or less!) than just two forms, singular and plural. Slavic languages have 3, Arabic has 6, Japanese just 1. Your code could never work right with these languages.

    As is often the case, the GNU gettext manual discusses this issue in some detail:
    http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Plural-forms.html