-
-
Notifications
You must be signed in to change notification settings - Fork 138
Open
Description
First of all, thank you for a library. Second, I don't know how to load multiple *.mo translation files and use them with textdomain context.
This is my code so far:
use Gettext\Translator;
use Gettext\Loader\MoLoader;
$lang = 'sk' // set by a side function
define('ROOT', '/path/to/root');
function __( string $string, string $textdomain = null ) {
static $t = null;
global $basic_lang;
$translation = ROOT . '/languages/' . $lang . '.mo';
if (!file_exists( $translation )) {
return $string;
}
if ($t === null) {
$loader = new MoLoader();
$t = Translator::createFromTranslations( $loader->loadFile( $translation ) );
}
//return $textdomain ? $t->dgettext( $textdomain, $string ) : $t->gettext( $string );
return $t->gettext( $string );
}
//echo __( 'Buy a ticket', 'reservation' ); // does not work right now, how to make it work?
echo __( 'Buy a ticket' ); // works
I guess that mode code samples would be helpful for others too.
Metadata
Metadata
Assignees
Labels
No labels