diff --git a/assets/javascripts/wizard/lib/wizard-i18n.js.es6 b/assets/javascripts/wizard/lib/wizard-i18n.js.es6 index fdefab77..9b9f8dd9 100644 --- a/assets/javascripts/wizard/lib/wizard-i18n.js.es6 +++ b/assets/javascripts/wizard/lib/wizard-i18n.js.es6 @@ -13,6 +13,11 @@ const getThemeId = () => { } }; +const getThemeKey = (key) => { + const themeId = getThemeId(); + return `theme_translations.${themeId}.${key}`; +}; + const translationExists = (key) => { return ( I18n.findTranslation(key, { locale: I18n.locale }) || @@ -20,13 +25,20 @@ const translationExists = (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); } - const themeKey = `theme_translations.${themeId}.${key}`; + let themeKey = getThemeKey(key); if (translationExists(themeKey)) { return I18n.t(themeKey, params);