-
-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translating empty string #182
Comments
In theory, these messages are parsed as headers. Do you have an example of po file that is not parsed correctly? |
So a little background first: we were using the I've attached a sample .po and resulting .mo file. Loading that .mo file and requesting it translates empty string. In an interactive shell: php > $translations = Gettext\Translations::fromMoFile(__DIR__ . '<resourcedir>/checkout.nl.mo');
php > $translations->setLanguage('nl');
php > $translations->setDomain('checkout');
php > $t = new Gettext\Translator();
php > $t->loadTranslations($translations);
php > echo $t->dpgettext('checkout', '', '');
Project-Id-Version: <redacted-id>
Report-Msgid-Bugs-To:
Last-Translator: <redacted-name> <redacted-email>, 2018
Language-Team: Dutch (<redacted-url>)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
POT-Creation-Date: 2018-05-18 08:45+0000
PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
Language: nl
Plural-Forms: nplurals=2; plural=n != 1;
X-Domain: checkout We can of course prevent this in our own wrapper, but I thought it would be nice as Gettext itself prevented leaking headers in the first place (as apparently |
Ok, I see. $filename = 'translations/checkout.nl.php';
$translations->toPhpArrayFile($filename, ['includeHeaders' => false]);
$t = new Gettext\Translator();
$t->loadTranslations($filename); The option Maybe the translator could include the 'includeHeaders = false' option to generate the array internally, instead use the default config. I'll change it in the new version. |
v4.6.0 released including a fix for this. |
In po and mo files (I don't know about others), the message with empty string as id contains the file headers. These should never be returned as a translation. Is it an idea to either
a. leave them out during the reading of the file, or
b. just return empty string when translation of key empty string is requested?
I'm willing to make a PR myself if you agree with either of the options, or interested in possible other solutions.
The text was updated successfully, but these errors were encountered: