0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-30 12:31:10 +01:00
discourse-custom-wizard/assets/javascripts/wizard/lib/wizard-i18n.js.es6

51 Zeilen
1 KiB
Text

import I18n from "I18n";
const getThemeId = () => {
2021-06-27 13:32:19 +02:00
let themeId = parseInt(
document.querySelector("meta[name=discourse_theme_id]").content,
10
);
if (!isNaN(themeId)) {
return themeId.toString();
} else {
return null;
}
};
const translationExists = (key) => {
return (
I18n.findTranslation(key, { locale: I18n.locale }) ||
I18n.findTranslation(key, { locale: I18n.defaultLocale })
);
};
2021-09-14 05:33:16 +02:00
const getThemeKey = (key) => {
const themeId = getThemeId();
return `theme_translations.${themeId}.${key}`;
};
const translatedText = (key, value) => {
const themeKey = getThemeKey(key);
return translationExists(themeKey) ? I18n.t(themeKey) : value;
};
export { translatedText };
const WizardI18n = (key, params = {}) => {
const themeId = getThemeId();
if (!themeId) {
return I18n.t(key, params);
}
2021-09-14 05:33:16 +02:00
let themeKey = getThemeKey(key);
if (translationExists(themeKey)) {
return I18n.t(themeKey, params);
} else {
return I18n.t(key, params);
}
};
export default WizardI18n;