Search code examples
phpgettext

Gettext() with larger texts


I'm using gettext() to translate some of my texts in my website. Mostly these are short texts/buttons like "Back", "Name",...

// I18N support information here
$language = "en_US";
putenv("LANG=$language");
setlocale(LC_ALL, $language);


// Set the text domain as 'messages'
$domain = 'messages';
bindtextdomain($domain, "/opt/www/abc/web/www/lcl");
textdomain($domain);

echo gettext("Back");

My question is, how 'long' can this text (id) be in the echo gettext("") part ?

Is it slowing down the process for long texts? Or does it work just fine too? Like this for example:

echo _("LZ adfadffs is a VVV contributor who writes a weekly column for Cv00m. The former Hechinger Institute Fellow has had his commentary recognized by the Online News Association, the National Association of Black Journalists and the National ");

Solution

  • The official gettext documentation merely has this advice:

    Translatable strings should be limited to one paragraph; don't let a single message be longer than ten lines. The reason is that when the translatable string changes, the translator is faced with the task of updating the entire translated string. Maybe only a single word will have changed in the English string, but the translator doesn't see that (with the current translation tools), therefore she has to proofread the entire message.

    There's no official limitation on the length of strings, and they can obviously exceed at least "one paragraph/10 lines".

    There should be virtually no measurable performance penalty for long strings.