diff --git a/src/Store.ts b/src/Store.ts index f966c91e1..c9231895b 100644 --- a/src/Store.ts +++ b/src/Store.ts @@ -41,6 +41,7 @@ import type IndicatorImp from './component/Indicator' import type { IndicatorCreate, IndicatorFilter, IndicatorOverride } from './component/Indicator' import type OverlayImp from './component/Overlay' import { OVERLAY_ID_PREFIX, type OverlayCreate, type OverlayFigure, type OverlayFilter, type OverlayOverride } from './component/Overlay' +import { getSupportedLocales } from './extension/i18n/index' import { getIndicatorClass } from './extension/indicator/index' import { getOverlayInnerClass } from './extension/overlay/index' import { getStyles as getExtensionStyles } from './extension/styles/index' @@ -481,6 +482,11 @@ export default class StoreImp implements Store { } setLocale(locale: string): void { + if (!getSupportedLocales().includes(locale)) { + logWarn('', '', `Locale ${locale} is not supported, fallback to en-US.`) + this._locale = 'en-US' + return + } this._locale = locale } diff --git a/src/extension/i18n/index.ts b/src/extension/i18n/index.ts index 9090ff134..a199d446e 100644 --- a/src/extension/i18n/index.ts +++ b/src/extension/i18n/index.ts @@ -30,7 +30,7 @@ function getSupportedLocales(): string[] { } function i18n(key: string, locale: string): string { - return locales[locale][key] ?? key + return locales[locale]?.[key] ?? key } export { getSupportedLocales, i18n, registerLocale }