Skip to content

Commit

Permalink
Merge branch 'Blockrain.issues' of https://github.com/Vishalk91-4/sug…
Browse files Browse the repository at this point in the history
…arizer into pr/1385
  • Loading branch information
Lionel Laské committed Aug 19, 2023
2 parents 9708e49 + d6d0932 commit 2cc6514
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 52 deletions.
98 changes: 48 additions & 50 deletions activities/Blockrain.activity/lib/l10n.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
define(['i18next.min', 'axios.min'], function (i18next, axios) {
const l10n = {};
let initialized = false;
const l10n = {language: {direction: "ltr"}};

l10n.init = async (lang) => {
await i18next.init({
lng: lang,
debug: false,
fallbackLng: "en",
resources: {}
}).then(() => {
l10n.switchTo(lang);
});
};
l10n.init = async (lang) => {
await i18next.init({
lng: lang,
fallbackLng: "en",
resources: {}
}).then(() => {
l10n.language.direction = i18next.dir();
l10n.switchTo(lang);
});
};

l10n.get = (key) => {
return i18next.t(key);
};
l10n.get = (key, parameter) => {
return i18next.t(key, parameter);
};

l10n.loadLanguageResource = (lang) => {
return new Promise((resolve, reject) => {
axios.get("./locales/" + lang + ".json").then((response) => {
resolve(response.data);
}).catch((error) => {
console.log("Failed to load " + lang + " language: " + error);
resolve(null); // Resolve with null to indicate failure
});
});
};
l10n.loadLanguageResource = (lang) => {
return new Promise((resolve, reject) => {
axios.get("./locales/" + lang + ".json").then((response) => {
resolve(response.data);
}).catch((error) => {
console.log("Failed to load " + lang + " language: " + error);
resolve(null); // Resolve with null to indicate failure
});
});
};

l10n.switchTo = (lang) => {
if (!i18next.hasResourceBundle(lang, "translation")) {
console.log("Loading " + lang + " language");
l10n.loadLanguageResource(lang).then((locales) => {
if (locales !== null) {
i18next.addResourceBundle(lang, "translation", locales);
} else {
l10n.init("en");
}
i18next.changeLanguage(lang);
initialized = true;
triggerLocalizedEvent();
});
} else {
i18next.changeLanguage(lang);
initialized = true;
triggerLocalizedEvent();
}
};
l10n.switchTo = (lang) => {
if (!i18next.hasResourceBundle(lang, "translation")) {
console.log("Loading " + lang + " language");
l10n.loadLanguageResource(lang).then((locales) => {
if (locales !== null) {
i18next.addResourceBundle(lang, "translation", locales);
i18next.changeLanguage(lang);
triggerLocalizedEvent();
} else {
l10n.init("en");
}
});
} else {
i18next.changeLanguage(lang);
triggerLocalizedEvent();
}
};

function triggerLocalizedEvent() {
const event = new Event("localized");
window.dispatchEvent(event);
};

return l10n;
});
function triggerLocalizedEvent() {
const event = new Event("localized");
window.dispatchEvent(event);
};

return l10n;
});
3 changes: 1 addition & 2 deletions activities/Blockrain.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ define(function () {
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
setTimeout(function () {
var environmentValue = window.top.sugar.environment;
callback(null, environmentValue);
callback(null, window.top.sugar.environment);
}, 0);
}
} else if (env.isStandalone()) {
Expand Down

0 comments on commit 2cc6514

Please sign in to comment.