2

I am trying to translate a theme using Poedit, every thing is alright except two strings which give me errors like this:

Error: 'msgstr' is not a valid PHP format string, unlike 'msgid'. Reason: The character that terminates the directive number 1 is not a valid conversation specifier.

The string itself is this:

% comments

Both errors are in strings having % comment (not sth like % s). Now I have two problems: 1. How can I resolve these errors? Do I need to change theme code? 2. After getting these compile errors, I used .mo and .po files anyway but some phrases had been translated and some not! What is the reason to this?

EDIT: The PHP code translation associated to is:

comments_number( __('There are no comments so far', 'hbthemes'), __('There is <strong>1 comment</strong> so far', 'hbthemes'), __('There are <strong>% comments</strong> so far', 'hbthemes') );
0

The % character is a special character in the gettext translation functions. To escape the % character to use it in a string, change it to %%.

If you weren't using the __() translation functions, then a single % character would give you the number of comments. However, when you are using the translation functions, % is a special character with special meaning. If you want to actually include a % character in the string, you need to type it as %%. The __() function will send a single % on to the comments_number function, and you should get the number of comments in its place.

Your comments_number function should be:

comments_number( __('There are no comments so far', 'hbthemes'), __('There is <strong>1 comment</strong> so far', 'hbthemes'), __('There are <strong>%% comments</strong> so far', 'hbthemes') );
  • %% would show comments number? So what is the difference between single and double %? – Mehraban Sep 21 '13 at 7:51
  • @SAM I updated the answer with further explanation. – Ben Miller - Reinstate Monica Sep 21 '13 at 12:22
  • Changing % to %% made comment count double. It shows 2 comments 22 comments. – Mehraban Sep 21 '13 at 20:08
0

The problem was with POEdit program. I used another app and it's gone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.