Skip to content
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

fix: prevent race condition between i18next causing translation to fail #341

Merged
merged 1 commit into from
Feb 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions client/modules/i18n/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import i18next, { getLabelsFor, getValidationErrorMessages, i18nextDep } from ".

const { i18nBaseUrl } = Meteor.settings.public;

// Keep track of current langage.
let currentLanguage = null;
const configuredI18next = i18next
// https://github.com/i18next/i18next-browser-languageDetector
// Sets initial language to load based on `lng` query string
Expand Down Expand Up @@ -107,9 +109,12 @@ Meteor.startup(() => {
Tracker.autorun(() => {
const shopId = Reaction.getPrimaryShopId();
const shop = shopId && Shops.findOne({ _id: shopId });
const shopLanguage = (shop && shop.language) || null;

initializeI18n(shopLanguage || "en");
const shopLanguage = (shop && shop.language) || "en";
// Only need to re-initialize if the language was switched
if (shopLanguage !== currentLanguage) {
currentLanguage = shopLanguage;
initializeI18n(shopLanguage);
}
});

//
Expand Down