diff --git a/src/common/models/locale/locale.mocha.ts b/src/common/models/locale/locale.mocha.ts index 4916693ad..2ce93c481 100644 --- a/src/common/models/locale/locale.mocha.ts +++ b/src/common/models/locale/locale.mocha.ts @@ -33,6 +33,12 @@ describe("locale", () => { expect(locale).to.deep.equal(en_us); }); + it("should return default locale if passed unrecognized base identifier", () => { + const locale = fromConfig({ base: "foobar" } as any); + + expect(locale).to.deep.equal(en_us); + }); + it("should use base locale and override desired fields", () => { const locale = fromConfig({ base: "en-US", overrides: { weekStart: 42 } }); diff --git a/src/common/models/locale/locale.ts b/src/common/models/locale/locale.ts index 278c1fdf2..0ffe34b56 100644 --- a/src/common/models/locale/locale.ts +++ b/src/common/models/locale/locale.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { isObject } from "../../utils/general/general"; +import { LOGGER } from "../../logger/logger"; +import { isObject, isTruthy } from "../../utils/general/general"; const enUS: Locale = { shortDays: ["S", "M", "T", "W", "T", "F", "S"], @@ -48,6 +49,10 @@ export interface Locale { export function fromConfig(locale?: LocaleJS): Locale { if (!isObject(locale)) return DEFAULT_LOCALE; const { base, overrides } = locale; + if (!isTruthy(LOCALES[base])) { + LOGGER.warn(`Unsupported locale identifier: ${base}. Fallback to en-US.`); + return DEFAULT_LOCALE; + } return { ...LOCALES[base], ...overrides