get text PHP5 don't work on debian

2019-05-18 18:26发布

问题:

I'm developing a web site which use gettext. Every thing work great in local. But today I've upload my web site on my production server and gettext don't want to work anymore. The language I'd like to use are fr_FR and en_US. gettext translate my text if I display my web site in french but nothing happen for the english.

When I execute locale -a on my debian server, I get:

C
fr_FR.utf8
POSIX

I'm french so I think every thing is normal. But when I do: locale-gen en_US or locale-gen en_US.UTF-8 and then locale -a again, nothing change. ! Is that normal ?

Here is a sample of PHP code just in case. But since gettext work for the french language, I believe the problem is not here.

$langage = 'en_US.utf8';
putenv("LC_ALL=$langage"); 
setlocale(LC_ALL, $langage); 

$languageFileName = "default"; // locale/en_US/LC_MESSAGES/default.mo
bindtextdomain($languageFileName, PATH.'/locale'); 
bind_textdomain_codeset($languageFileName, 'UTF-8');
textdomain($languageFileName);

Thanks a lot in advance for the help.

回答1:

Well, I've find the solution to my problem. I've edited the file /etc/locale.gen and uncomment the language I'd like to use with gettext. Then I've run locale-gen. That's it !

Still don't understand why locale-gen en_US.UTF-8 didn't do the same thing. I'm using debian 6 Squeeze.



回答2:

You need to on the php extension php_gettext.