To translate my PHP app I use compiled in gettext module. Here is a directory tree of translations made according to docs:
locale/
cs_CZ/
LC_MESSAGES/
messages.po
messages.mo
de_DE/
LC_MESSAGES/
messages.po
messages.mo
fr_FR/
LC_MESSAGES/
messages.po
messages.mo
Question: is it possible to get rid of LC_MESSAGES catalog? Will PHP be able to find translations if I use this structure?
locale/
cs_CZ/
messages.po
messages.mo
de_DE/
messages.po
messages.mo
fr_FR/
messages.po
messages.mo
My PHP that switches translations:
<?php
setlocale(LC_ALL, 'fr_FR.UTF-8');
bindtextdomain("messages", "locale");
bi开发者_运维百科nd_textdomain_codeset("messages", 'UTF-8');
textdomain("messages");
?>
Thank you in advance.
The only feasible workaround is creating a symlink LC_MESSAGES -> .
in each language subdirectory. (But this complicates PHP application installation. FTP seldomly can create symlinks.)
I'm afraid LC_MESSAGES
is a requirement.
Correct me if I'm wrong, but I think it has something to do with the gettext cache.
If you really want to do that, you can use this composer package : gettext/gettext
So you can have the folder organization as you desire or even something like that :
locales/
cs_CZ.mo
cs_CZ.po
de_DE.mo
de_DE.po
fr_FR.mo
fr_FR.po
Answering the question in the title: it does require.
Why?
To my current understanding, LC_MESSAGES
is one of the many localization categories you could use with gettext. You can change to another category using dcgettext()
, for instance.
However, that's a bit confusing since gettext is supposed to be mainly used for text translation, and it might be weird to use it to localize dates, money, numbers or charsets.
精彩评论