The below is quoted from here:
<?php
$directory = dirname(__FILE__).'/locale';
$domain = 'mydomain';
$locale ="pt_BR.utf8";
//putenv("LANG=".$locale); //not needed for my tests, but people say it's useful for windows
setlocale( LC_MESSAGES, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
But what’s it doing ?
textdomain()specifically is about switching between multiple text sources. In web applications you typically only have one textdomain, because it’s often just one big application.You would use it if your application is separated into multiple modules. The advantage is that the translation texts (.mo and .po) files could be edited and updated separately for each application part.
And when switching between modules, each can reset its domain:
vs
There is also a shortcut for that purpose:
In the common case you use
textdomain()however just with the main applicaiton name. This then became the basename for the transaltion sourcesmyapp.mo: