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.
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.
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.
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.
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.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With