<\/script>')

Use multiple domains in gettext in PHP application

By domain I mean the gettext domain. I have this code

$domain = "default";
$locale = 'en_US';
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain($domain, 'my_path'); 
bind_textdomain_codeset($domain, 'UTF-8');    
textdomain($domain);

      

So it will use my_path / en_US / LC_MESSAGES / default.po

But I want to use more than one file so that I can override the default .po overwrite with another po file like admin.po, blog.po, etc.

+3


source to share


1 answer


First, define all your domains something like this:

bindtextdomain('domain1', DIR_LOCALE);
bindtextdomain('domain2', DIR_LOCALE);
bindtextdomain('domain3', DIR_LOCALE);
textdomain('domain1'); // set default domain for _() function

      



Now, if you want to grab rows from a different domain, you must use either dgettext()

or dcgettext()

(if not from LC_MESSAGES

) to retrieve just one row from another specified domain. Example:

echo dgettext('domain2', "msgid");

      

+16


source







All Articles