2

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Paddy Hallihan
  • 1,624
  • 3
  • 27
  • 76

3 Answers3

2

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.

Guido Flohr
  • 1,871
  • 15
  • 28
1

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.

Paddy Hallihan
  • 1,624
  • 3
  • 27
  • 76
  • 2
    It would work but it's a hack that requires manual interaction, whenever you generate a new version of the `.po` file. Besides, the format specifications are meaningful and it is important that they are checked for syntactical correctness, when you run `msgfmt --check` to compile the `.po` files. – Guido Flohr Aug 23 '18 at 10:41
0

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.

Tama
  • 181
  • 1
  • 6