What is bindtextdomain, textdomain in gettext?

I studied a little gettext, but I can not understand these two functions. I was wondering if I can use multiple translations in APP written in PHP. For example, I have 1) translation of the system 2) translations of extensions 3) translations in order to separate them in different files. My question is that if I download the system translation, then download the theme translation, the first one will be โ€œuninstalledโ€?

I would appreciate any links related to gettext and php.

thanks

+6
php gettext php-gettext
source share
1 answer

You can easily switch between text domains whenever you want. eg:

Considering

./locale/en/LC_MESSAGES/template.po 

with content

 msgid "foo" msgstr "foobar" 

and

 ./locale/en/LC_MESSAGES/messages.po 

with content

 msgid "Basic test" msgstr "A basic test" 

You can use something like the following PHP code to switch from one text domain to another and then back:

 <?php setlocale(LC_ALL, 'en_US.UTF-8'); bindtextdomain ("messages", "./locale"); bindtextdomain ("template", "./locale"); textdomain ("messages"); echo gettext("Basic test"), "\n"; textdomain ("template"); echo _("foo"), "\n"; textdomain ("messages"); echo gettext("Basic test"), "\n"; 
+23
source share

All Articles