问题
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");
bind_textdomain_codeset("messages", 'UTF-8');
textdomain("messages");
?>
Thank you in advance.
回答1:
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.)
回答2:
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.
回答3:
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
来源:https://stackoverflow.com/questions/4192503/php-does-gettext-require-lc-messages-dirs