-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to load multiple *.mo files (general and for specific textdomain) #272
Comments
As I can see, you're loading only one domain, but in gettext every domain is a different file. Maybe something like this: $loader = new MoLoader();
$lang = "sk";
$default = $loader->loadFile(ROOT."/languages/{$lang}/default.mo";
$reservation = $loader->loadFile(ROOT."/languages/{$lang}/reservation.mo";
$t = Translator::createFromTranslations($default, $reservation); |
Oka, thank you for a code sample. And when I have more textdomains (files), like 'forum' loading also forum would be:
I would like to load forum.mo only when user interacts with forum controller otherwise it has no sense to split translated strings into multiple .mo files (textdomain). Can you direct me to some tutorial or code example? NOTE: Maybe I asking stupid questions from your point of you but I'm new within gettext environment / system / ... |
You can see the code of how create a translator and add translations here: https://github.com/php-gettext/Translator/blob/master/src/Translator.php#L15 A pseudocode (not tested): $loader = new MoLoader();
$arrayGenerator = new ArrayGenerator();
// Check if the domain hasn't loaded before
if (empty($domains[$domain])) {
// Load the translations of this domain:
$translations = $loader->loadFile(ROOT."/languages/{$lang}/${domain}.mo";
// Convert the translations to an array:
$array = $arrayGenerator->generateArray($translations);
//Add the array of translations to the translator
$t->addTranslations($array);
//Mark the domain as loaded
$domains[$domain] = true;
} |
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:
I guess that mode code samples would be helpful for others too.
The text was updated successfully, but these errors were encountered: