Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/extension/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }