2020-11-26 06:45:30 +01:00
|
|
|
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
|
|
|
|
);
|
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
|
|
|
|
2022-06-15 09:10:33 +02:00
|
|
|
const getThemeKey = (key) => {
|
|
|
|
const themeId = getThemeId();
|
|
|
|
return `theme_translations.${themeId}.${key}`;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2022-06-15 09:10:33 +02:00
|
|
|
const translatedText = (key, value) => {
|
|
|
|
const themeKey = getThemeKey(key);
|
|
|
|
return translationExists(themeKey) ? I18n.t(themeKey) : value;
|
|
|
|
};
|
|
|
|
|
|
|
|
export { translatedText };
|
|
|
|
|
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
|
|
|
|
2022-06-15 09:10:33 +02:00
|
|
|
let themeKey = getThemeKey(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;
|