Search code examples
phphtmlgettexthtml-entitiespoedit

Gettext & POedit - Errors validating files with '%'


I am getting a few different errors for strings in POedit that have a '%' symbol.

First:

a format specification for argument 1 doesn't exist in 'msgstr'

Second:

msgstr is not a valid PHP string, unlike 'msgid'. Reason: In the directive number 1, the character 'a' is not a valid conversion specifier.

In this case 'a' is the letter after the '%' symbol. (e.g. '100% stainless steel' becomes '100% acier inoxydable')

To try resolve this I have tried:

1) Adding the following lines to the .po file header:

"Content-Type: text/plain; charset=UTF-8\n"
"X-Poedit-SourceCharset: UTF-8\n"

2) Using %% to instead of '%' in the translation string as per How can I escape '%' character in a gettext string?

3) Using & #37 ; instead of '%' in the translation string.

4) Using 'percent' instead of '%' in the translation string.

Am I missing something or should I replace all instances of '%' in the source text?

Edit

So I tried messing around with my source text.

I replaced '%' with '%%' in my source and was able to put in '& #37 ;' into the translation and the .po file validated.

But.... it doesn't work, my english version now just has '%%' on the front end and it won't translate into any language.

Note

The '& #37 ;' doesn't actually have spaces in it, it just displays as % if I don't put them there so I can't show an example.


Solution

  • So when you validate a file in POedit, if there is this type of error it adds something like this to the actual file:

    #, php-format
    

    Just leaving the '%' the way it was and removing this seems to work although I'm not sure if this will cause issues down the line.