A platform for community discussion. Free, open, simple.
DEV: Improve error messages for legacy theme helpers in gjs (#29191)
David Taylor182689b6bb0d
diff --git a/app/assets/javascripts/discourse/app/helpers/theme-i18n.js b/app/assets/javascripts/discourse/app/helpers/theme-i18n.jsindex 11fffb8522b..5756eca4a36 100644--- a/app/assets/javascripts/discourse/app/helpers/theme-i18n.js+++ b/app/assets/javascripts/discourse/app/helpers/theme-i18n.js@@ -3,5 +3,12 @@ import I18n from "discourse-i18n";registerRawHelper("theme-i18n", themeI18n);export default function themeI18n(themeId, key, params) {+ if (typeof themeId !== "number") {+ throw new Error(+ `The theme-i18n helper is not supported in this context.\n\n` ++ `In a theme .gjs file, use '{{i18n (themePrefix "${themeId}")}}' instead.\n\n` ++ `'themePrefix' is available automatically, and does not need to be imported.\n`+ );+ }return I18n.t(`theme_translations.${themeId}.${key}`, params);}diff --git a/app/assets/javascripts/discourse/app/helpers/theme-setting.js b/app/assets/javascripts/discourse/app/helpers/theme-setting.jsindex 8c3b08275e9..870ff0de51b 100644--- a/app/assets/javascripts/discourse/app/helpers/theme-setting.js+++ b/app/assets/javascripts/discourse/app/helpers/theme-setting.js@@ -3,5 +3,12 @@ import { registerRawHelper } from "discourse-common/lib/helpers";registerRawHelper("theme-setting", themeSetting);export default function themeSetting(themeId, key) {+ if (typeof themeId !== "number") {+ throw new Error(+ `The theme-setting helper is not supported in this context.\n\n` ++ `In a theme .gjs file, use '{{settings.${themeId}}}' instead.\n\n` ++ `'settings' is available automatically, and does not need to be imported.\n`+ );+ }return getThemeSetting(themeId, key);}