0
votes

I've encountered a translation issue for the given source;

<?php
$this->messageAdd($this->_("Ett okänt fel uppstod när %0 skulle skapas!", $term2), "error");
return $this->setResultCode(self::RESULT_ERROR);
?>

If I'm not blind this is a completely normal string and I have many alike in other source files but this specific one causes these lines in the po file;

#: ../../../../path/to/source_file.php:552
#, php-format
msgid "Ett okänt fel uppstod när %0 skulle skapas!"
msgstr "An unknown error occurred while creating the %0!"

With the error

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

What is the issue and why is it that only this string causes the error? If I remove the string from the source file no errors are generated in poedit.

Edit #1; I found this issue after further research and found that adding the comment /* xgettext:no-php-format */ before the translation string in the source file fixed the problem. It would be nice though to know why this happens only to the specified string and not to any other of my 5k+ strings.

1
Because xgettext uses a heuristic that is, presumably, triggered by the use of % in the string (which you, presumably, don't use in all that 5k+ strings). Heuristics — by definition — occasionally fail and that's why gettext has builtin support for correcting them manually.Václav Slavík
@VáclavSlavík Ok thank you. True, I don't use % in all strings but I did a script-count and 3219 strings have one or more %[0-9] entities in them. So I'm still unsure as to why only the given string is causing the error. Anyhow, the inline comment works.Daniel

1 Answers

1
votes

Remove

#, php-format

directive from your .po files.