7

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 ");
Nicolas.
  • 453
  • 1
  • 5
  • 27

3 Answers3

7

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.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • Ok so one paragraph or 10 lines is already pretty long (in my case). I was wondering about 'longer strings' like 40-50 words versus short strings, like 5-10 words. So if I got it right 50 words should not be a big problem. – Nicolas. Aug 15 '13 at 09:47
2

gettext effectively has a limit of 4096 chars on the length of strings.

When you pass this limit you get a warning:

Warning: gettext(): msgid passed too long in %s on line %d

and returns you bool(false) instead of the text.

Source: PHP Interpreter repository - The real fix for the gettext overflow bug

roz
  • 21
  • 2
  • 2
0

function gettext http://www.php.net/manual/en/function.gettext.php

it's defined as a string input so your machines memory would be the limiting factor.

try to benchmark it with microtime or better with xdebug if you have it on your development machine.

Raymond Nijland
  • 11,488
  • 2
  • 22
  • 34