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.
This commit is contained in:
David Taylor 2024-10-14 16:00:56 +01:00 committed by GitHub
parent 492cf52bab
commit 182689b6bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);
}