From 47eed48ad5d8d3c9b7b06cc07d8a33e86b7eae53 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 15 Jun 2022 09:10:33 +0200 Subject: [PATCH] Update wizard-i18n.js.es6 --- assets/javascripts/wizard/lib/wizard-i18n.js.es6 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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);