diff --git a/packages/core/src/i18n.test.ts b/packages/core/src/i18n.test.ts index 5deccfe63..1f09c38e9 100644 --- a/packages/core/src/i18n.test.ts +++ b/packages/core/src/i18n.test.ts @@ -290,6 +290,23 @@ describe("I18n", () => { expect(handler).toHaveBeenCalledTimes(2) }) + it("._ should emit missing event for undefined id", () => { + const i18n = setupI18n({ + locale: "en", + messages: { en: {} }, + }) + + const handler = jest.fn() + i18n.on("missing", handler) + // @ts-expect-error 'id' should be of 'MessageDescriptor' or 'string' type. + i18n._() + expect(handler).toHaveBeenCalledTimes(1) + expect(handler).toHaveBeenCalledWith({ + id: "", + locale: "en", + }) + }) + describe("params.missing - handling missing translations", () => { it("._ should return custom string for missing translations", () => { const i18n = setupI18n({ diff --git a/packages/core/src/i18n.ts b/packages/core/src/i18n.ts index feaf8f9f5..ed04e9368 100644 --- a/packages/core/src/i18n.ts +++ b/packages/core/src/i18n.ts @@ -213,6 +213,11 @@ export class I18n extends EventEmitter { options?: MessageOptions ): string { let message = options?.message + + if (!id) { + id = "" + } + if (!isString(id)) { values = id.values || values message = id.message