2
votes

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.

3

3 Answers

2
votes

Short of an example in your source code and your resulting .po file, I can only guess. You can probably fix your problem in the sources like this:

/* xgettext: no-php-format */
echo(gettext("string with % sign"));

I'm not a PHP programmer. Excuse me if the syntax is wrong.

The xgettext: special comments are documented (kind of ...) at https://www.gnu.org/software/gettext/manual/html_node/c_002dformat-Flag.html#c_002dformat-Flag.

1
votes

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.

0
votes

You can put in your source: % I think you can also use % but I haven't tried.

Remember that the problem arises if the % symbol is in the source, not in the translation. You can use % symbol in translations without errors.