Universe:i18n How to use runWithLocale() in Meteor 3?

Since I upgraded to Meteor 3 and universe:i18n@3.0.1, runWithLocale() does not work as expected (it worked fine on Meteor 2 with universe:i18n@1.32.6).

It neither picks the right text for the locale nor does it apply any parameters to the text, e.g. {$username}. It just returns the plain string for the default language, including the placeholders for any parameters.

Here’s how I call it:

const language = user?.language || 'en-US';
await runWithLocale(language, async () => {
    ...
}

Does anybody know what the correct syntax would be for Meteor 3? Or is this just a bug?

I need this to localize emails sent out to users, based on their language preferences.

What i18n.getLocale() returns to you?

i18n.runWithLocale(locale, func) docs says: locale must be loaded first (if it is not bundled)

It returns the correct locale. Interestingly, replacing the placeholders works now, and also one the language is being translated, but not the two others.

What exactly do you mean with “loaded first”?

1 Like

Ok, I think I found the issue. When I extended the number of languages, I forgot to import the new languages on server-side as well. My bad. Thanks for the hint.

1 Like