php-gettext / Gettext

PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
MIT License
687 stars 134 forks source link

load multiple domains ? #217

Closed quasiperfect closed 5 years ago

quasiperfect commented 5 years ago

hi

i have tried something like this and no luck

$locale = 'de_DE';
$translator = new GettextTranslator();
$translator->setLanguage($locale);

$translator->loadDomain($locale, './');
$translator->loadDomain($locale, './vendor/path/');
$translator->register();

any suggestions ?

oscarotero commented 5 years ago

You are loading the same domain twice. Note also that the domain is not the same than the language (de_DE). The directory of your domain should contain a subdirectory with the locale a sub-subdirectory with the category and then the .mo file with the same name that your domain name. For example:

$locale = 'de_DE';
$domain = 'messages';

$translator = new GettextTranslator();
$translator->setLanguage($locale);

$translator->loadDomain($domain, __DIR__'/Locale');
//Loads the file Locale/de_DE/LC_MESSAGES/messages.mo

See PHP gettext docs for more info.

quasiperfect commented 5 years ago

thanks @oscarotero