I’m trying to translate a theme for WordPress using Poedit. When I try to translate % comment
string, whether I use %
in translation or not, I get this error:
Error: ‘msgstr’ is not a valid PHP format string, unlike ‘msgid’.
Reason: The character that terminates the directive number 1 is not a valid conversion specifier.
That string’s resource is line below:
comments_number(
__( '0 comments' , 'hbthemes' ) ,
__( '1 comment' , 'hbthemes' ),
__( '% comments' , 'hbthemes' )
);
I took a look at gettext manual but didn’t understand what would make these error. At first I wondered how just a single %
could be in a format string, but the theme natively shows comments count correctly.
EDIT:
If I use %%
instead of %
in translation, the error remains and if I change it inside the PHP code, I get comments count twice, e.g. 22
instead of 2
.
UPDATE:
The documentation here says %
will be replaced by number of comments, so I think actual problem is with Poedit not the code.
The problem was with POEdit and by using another translation tool, I got what I was looking for.
What exactly are you trying to accomplish? It seems to me you are reinventing the wheel and doing it wrong way on top of it. It thinks you should use sprintf(__(‘%d comments’), get_comments_number()) and it wants to force you to have it correct. You should not translate it this way. I am not sure wordpress uses gettext itself. If it is, use ngettext(‘%d comment’, ‘%d comments’, get_comments_number()). That way, it will have correct forms for other languages, that differs between 1, 3 and 5 for example.
See http://codex.wordpress.org/Function_Reference/_n
maybe this way:
Problem is how WordPress has this designed, it cannot be translated well. It should help you if you remove #, php-format flag before this string in po file by hand. It will not try to validate sprintf format where it is not printf format.