Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: does gettext require LC_MESSAGES dirs?

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.

like image 484
Silver Light Avatar asked Nov 16 '10 09:11

Silver Light


People also ask

What does PHP gettext do?

gettext, an open source internationalization and localization system makes it possible. It works with multiple languages, including PHP, and makes the entire translation process easy to manage and maintain. In this tutorial, we will learn how to install, set up and create simple translations using PHP gettext.

Can PHP use gettext?

The gettext module in PHP only supports languages and language identifiers that are installed on your server. on the command line of your server (e.g., by logging in with SSH). The command may require admin privileges and maybe not work on a hosted shared server.

What is the gettext PHP extension?

Gettext Functions. bind_textdomain_codeset — Specify or get the character encoding in which the messages from the DOMAIN message catalog will be returned. bindtextdomain — Sets or gets the path for a domain. dcgettext — Overrides the domain for a single lookup.

What is localization PHP?

Localization in software engineering is the process of adapting the content of a system to a particular locale so the target audience in that locale can understand it. It is not just about changing content from one language to another.


2 Answers

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.)

like image 123
mario Avatar answered Oct 02 '22 14:10

mario


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.

like image 35
takeshin Avatar answered Oct 02 '22 14:10

takeshin