From 182689b6bb0d50b1cc0e4efeacdb618f95436076 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 14 Oct 2024 16:00:56 +0100 Subject: [PATCH] DEV: Improve error messages for legacy theme helpers in gjs (#29191) theme-setting and theme-i18n are not needed in `.gjs` files. This commit adds more helpful error messages to direct developers to the modern alternatives. --- app/assets/javascripts/discourse/app/helpers/theme-i18n.js | 7 +++++++ .../javascripts/discourse/app/helpers/theme-setting.js | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/app/assets/javascripts/discourse/app/helpers/theme-i18n.js b/app/assets/javascripts/discourse/app/helpers/theme-i18n.js index 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.js index 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); }