gettext does not translate everything


I have a problem with translating texts with gettext(). I’ve used poedit for translating the texts. Most of the strings get translated perfectly from english to finnish, but some multi-line strings that I use for automatic emails fail to translate and just show the english original. I’ve tried many different setlocale etc schemes, clearing the cache and restarting apache. I’m using PHP Version 5.3.3.

Here’s one way I’ve tried setting up the language, locale etc:

[php]$lang = “fi_FI.utf8”; // also tried fi_FI which seems to work identically

//setlocale(LC_ALL, “”);

setlocale(LC_NUMERIC, ‘en_US’); // decimal separator
bindtextdomain(‘messages’, ‘locale/nocache’); // flushes gettext cache
bindtextdomain(“messages”, “locale”);
bind_textdomain_codeset(‘messages’, ‘UTF-8’);

Here’s some strings:
[php]$subject = _(“Your new eTool account”); // gets translated fine

$message_template = gettext('Hi!

Link to eTool client form for #NAME#

Contact person: #CONTACTPERSON# #EMAIL#

Link: #FORM_URL#

'); // this is the one that doesn’t get translated

$comments = _(‘Comments:’); // gets translated fine

Here’s the problem translation from message.po:

#: gettext-test.php:22
#, fuzzy
msgid ""
"Hi! \n"
"Link to eTool client form for #NAME#\n"
"Contact person: #CONTACTPERSON# #EMAIL#\n"
"Link: #FORM_URL#\n"
msgstr ""
"Hei! \n"
"Linkki eTool asiakaslomakkeeseen asiakkaalle #NAME#\n"
"Yhteyshenkilö: #CONTACTPERSON# <#EMAIL#>\n"
"Linkki: #FORM_URL#\n"

It seems it might have something to do with the problem translation being multi-line, but haven’t been able to find anything useful to help with that. Gettext is supposed to support multi-line translations.

I may have solved the problem with a cumbersome workaround of turning all multi-line translations into single lines in the php-code. For that you need to use the double quotes and the \n newline sequence. I suspect the problem really is with poedit that leaves the first line of the multi-line ids as blank (msgid “”). This is a big disadvantage for gettext vs using arrays or database for translation. Otherwise gettext is very handy.

Sponsor our Newsletter | Privacy Policy | Terms of Service