2020-11-26 06:45:30 +01:00
|
|
|
import I18n from "I18n";
|
|
|
|
|
|
|
|
const getThemeId = () => {
|
|
|
|
let themeId = parseInt($("meta[name=discourse_theme_ids]")[0].content, 10);
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-11-26 06:45:30 +01:00
|
|
|
if (!isNaN(themeId)) {
|
|
|
|
return themeId.toString();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2021-03-28 11:06:49 +02:00
|
|
|
};
|
2020-11-26 06:45:30 +01:00
|
|
|
|
|
|
|
const translationExists = (key) => {
|
2021-03-28 11:06:49 +02:00
|
|
|
return (
|
|
|
|
I18n.findTranslation(key, { locale: I18n.locale }) ||
|
|
|
|
I18n.findTranslation(key, { locale: I18n.defaultLocale })
|
|
|
|
);
|
|
|
|
};
|
2020-11-26 06:45:30 +01:00
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
const WizardI18n = (key, params = {}) => {
|
2020-11-26 06:45:30 +01:00
|
|
|
const themeId = getThemeId();
|
2021-04-12 08:26:22 +02:00
|
|
|
if (!themeId) {
|
|
|
|
return I18n.t(key, params);
|
|
|
|
}
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-11-26 06:45:30 +01:00
|
|
|
const themeKey = `theme_translations.${themeId}.${key}`;
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-11-26 06:45:30 +01:00
|
|
|
if (translationExists(themeKey)) {
|
|
|
|
return I18n.t(themeKey, params);
|
|
|
|
} else {
|
|
|
|
return I18n.t(key, params);
|
|
|
|
}
|
2021-03-28 11:06:49 +02:00
|
|
|
};
|
2020-11-26 06:45:30 +01:00
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
export default WizardI18n;
|