Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gettext() with larger texts

Tags:

php

gettext

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 ");
like image 560
Nicolas. Avatar asked Aug 14 '13 10:08

Nicolas.


2 Answers

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.

like image 155
deceze Avatar answered Oct 15 '22 22:10

deceze


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

like image 33
roz Avatar answered Oct 15 '22 21:10

roz