Skip to content

Commit

Permalink
Merge pull request #1852 from BorderTech/feature/i18-port
Browse files Browse the repository at this point in the history
Feature/i18 port
  • Loading branch information
ricksbrown authored May 13, 2024
2 parents ef15cf2 + 491ee3a commit 53ec802
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 7 additions & 5 deletions wcomponents-theme/src/main/js/wc/debug/i18n.mjs
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ import arrayDiff from "wc/array/diff.mjs";
import debounce from "wc/debounce.mjs";

const checked = {};
const queueCheck = debounce(languages => {
const onload = debounce(languages => {
try {
const langs = languages || i18next.languages;
const langs = languages ? Object.keys(languages) : i18next.languages;
if (langs) {
for (let i = 0; i < langs.length; i++) {
let nextLang = langs[i];
@@ -18,10 +18,12 @@ const queueCheck = debounce(languages => {
} catch (ex) {
console.warn(ex); // don't die checking missing translations and other debug fluff
}
}, 1337); // this does not need to happen in a hurry
}, 10000); // this does not need to happen in a hurry

i18next.on("loaded", () => queueCheck());
queueCheck();
i18next.on("loaded", onload);
if (i18next.languages.length) {
onload(); // it seems to have already loaded something, so the onload event handler won't be triggered
}

/**
* Check for missing translations in this language's resource bundle.
12 changes: 8 additions & 4 deletions wcomponents-theme/src/main/js/wc/i18n/i18n.mjs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ const noop = function(key, ...args) {
},
GOOG_RE = /^(.+)-x-mtfrom-(.+)$/;

let initing;
let initingPromise;

/**
* Manages the loading of i18n "messages" from the relevant i18n "resource bundle".
@@ -106,14 +106,18 @@ const instance = {
*/
initialize: function(config) {
const conf = config || wcconfig.get("wc/i18n/i18n") || {};
initing = initI18next(i18next, conf).then(translate => {
if (initingPromise) {
return initingPromise;
}
const done = () => initingPromise = null;
initingPromise = initI18next(i18next, conf).then(translate => {
if (translate) {
this.get = translatorFactory(translate);
initing = null;
return translate;
}
});
return initing;
initingPromise.catch(done);
return initingPromise.then(done);
}
};

0 comments on commit 53ec802

Please sign in to comment.