PHP: do I need gettext LC_MESSAGES?

To translate my PHP application, I use the compiled gettext module. Here is the translation directory tree made in accordance with the documents:

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 the LC_MESSAGES directory? Can PHP 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");
?>

Thanks in advance.

+5
source share
3 answers

The only possible solution is to create a symbolic link LC_MESSAGES -> .in each language subdirectory. (But this complicates the installation of the PHP application. FTP can rarely create symbolic links.)

+4
source

, LC_MESSAGES - .

, , , - gettext.

+3

If you really want this, you can use this composer package: gettext / gettext

Thus, you can have a folder organization as you wish or even something like this:

locales/
   cs_CZ.mo
   cs_CZ.po
   de_DE.mo
   de_DE.po
   fr_FR.mo
   fr_FR.po
0
source

All Articles