Gettext in PHP requires setlocale(LC_MESSAGES, NULL) to be called -


when using php 5.5.9 on ubuntu, gettext isn't working although set correctly.

the lines use set gettext following ones:

putenv('lang=es_es.utf8'); setlocale(lc_messages, 'es_es'); bindtextdomain('messages', './i18n'); bind_textdomain_codeset('messages', 'utf-8'); textdomain('messages'); 

this should contain needed. gettext returning default locale's strings (the ones passed in), never correct translations.

calling locale -a lists languages needed, set correctly, too.

the phpinfo() proves gettext (and intl extension) installed correctly:

gettext support = enabled intl version = 1.1.0 icu version = 52.1 icu data version = 52.1 

ubuntu has been rebooted, of course.

and, finally, directory specified contain required translation files gettext.

to put short, seems set correctly -- doesn't work.

however, when add setlocale(lc_messages, null); before call setlocale(lc_messages, 'es_es');, gettext works.

can explain this? while os , php versions aren't latest anymore, don't know of bugs prevent gettext working on stack.

the solution feels dirty hack, , not feel comfortable rely on.

when call setlocale(lc_messages, null), uses locale name environment, it'll "es_es.utf8".

you can try call setlocale(lc_messages, "es_es.utf8") instead, or better
setlocale(lc_messages, array("es_es", "es_es.utf8"))


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -