Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is bindtextdomain, textdomain in gettext?

I've been learning a bit of gettext but I can't grasp those two functions. I've been wondering if I could use multiple translations in a APP written in PHP. For an instance, I've 1) the system translation 2) extensions translations 3) theme translations to divide those in different files. My question is, if I load the system translation, then load the theme translation will the first one be "unset"?

I'd appreciate any links related to gettext and php.

Thanks

like image 747
allenskd Avatar asked Jan 01 '10 17:01

allenskd


People also ask

How does bindtextdomain () work?

The bindtextdomain () function sets or gets the path for a domain. The domain. The directory path. An empty string means the current directory. If null, the currently set directory is returned. The full pathname for the domain currently being set, or false on failure. directory is nullable now.

What is bindtextdomain in Laravel?

#include <libintl.h> char * bindtextdomain (const char * domainname, const char * dirname); The bindtextdomain function sets the base directory of the hierarchy containing message catalogs for a given message domain. A message domain is a set of translatable msgid messages.

What does an empty string mean in bindtextdomain ()?

An empty string means the current directory. If null, the currently set directory is returned. The full pathname for the domain currently being set, or false on failure. directory is nullable now. Previously, it was not possible to retrieve the currently set directory. The bindtextdomain () information is maintained per process, not per thread.

What is gettext in Python?

Source code: Lib/gettext.py. The gettext module provides internationalization (I18N) and localization (L10N) services for your Python modules and applications. It supports both the GNU gettext message catalog API and a higher level, class-based API that may be more appropriate for Python files.


1 Answers

You can readily swap between textdomains whenever you like. e.g:

Given

./locale/en/LC_MESSAGES/template.po 

with the contents

msgid "foo"
msgstr "foobar"

and

./locale/en/LC_MESSAGES/messages.po

with the contents

msgid "Basic test"
msgstr "A basic test"

You could use something like the following PHP code to switch from one textdomain to the other, 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";
like image 105
TML Avatar answered Sep 24 '22 10:09

TML