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-02-24 08:43:35 +01:00
|
|
|
|
2020-11-26 06:45:30 +01:00
|
|
|
if (!isNaN(themeId)) {
|
|
|
|
return themeId.toString();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2021-02-24 08:43:35 +01:00
|
|
|
};
|
2020-11-26 06:45:30 +01:00
|
|
|
|
|
|
|
const translationExists = (key) => {
|
2021-02-24 08:43:35 +01:00
|
|
|
return (
|
|
|
|
I18n.findTranslation(key, { locale: I18n.locale }) ||
|
|
|
|
I18n.findTranslation(key, { locale: I18n.defaultLocale })
|
|
|
|
);
|
|
|
|
};
|
2020-11-26 06:45:30 +01:00
|
|
|
|
2021-02-24 08:43:35 +01:00
|
|
|
const WizardI18n = (key, params = {}) => {
|
2020-11-26 06:45:30 +01:00
|
|
|
const themeId = getThemeId();
|
|
|
|
if (!themeId) return I18n.t(key, params);
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-11-26 06:45:30 +01:00
|
|
|
const themeKey = `theme_translations.${themeId}.${key}`;
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-11-26 06:45:30 +01:00
|
|
|
if (translationExists(themeKey)) {
|
|
|
|
return I18n.t(themeKey, params);
|
|
|
|
} else {
|
|
|
|
return I18n.t(key, params);
|
|
|
|
}
|
2021-02-24 08:43:35 +01:00
|
|
|
};
|
2020-11-26 06:45:30 +01:00
|
|
|
|
2021-02-24 08:43:35 +01:00
|
|
|
export default WizardI18n;
|