diff --git a/packages/firebaseui-core/src/config.ts b/packages/firebaseui-core/src/config.ts index 235abdfd..d9da7e1a 100644 --- a/packages/firebaseui-core/src/config.ts +++ b/packages/firebaseui-core/src/config.ts @@ -59,15 +59,18 @@ export function initializeUI(config: FirebaseUIConfigurationOptions, name: strin config.translations ??= []; - // TODO: Is this right? - config.translations.push(english); - - const translations = config.translations?.reduce((acc, translation) => { - return { - ...acc, - [translation.locale]: translation.translations, - }; - }, {} as TranslationsConfig); + // Map the translations to a TranslationsConfig object. + // If no translations are provided, use the English translations as default. + const translations = config.translations?.reduce( + (acc, translation) => { + return { + ...acc, + [translation.locale]: translation.translations, + }; + }, + //TODO: Do we always want to include English here? + { [english.locale]: english.translations } as TranslationsConfig + ); $config.setKey( name, diff --git a/packages/firebaseui-core/tests/unit/translations.test.ts b/packages/firebaseui-core/tests/unit/translations.test.ts index d7e26ad4..803c73d0 100644 --- a/packages/firebaseui-core/tests/unit/translations.test.ts +++ b/packages/firebaseui-core/tests/unit/translations.test.ts @@ -142,4 +142,29 @@ describe('getTranslation', () => { const translation = getTranslation(mockUi as any, 'errors', 'userNotFound'); expect(translation).toBe('No account found with this email address'); }); + + it('should allow custom en-US translation to overwrite the default one', () => { + const customEnUs = { + locale: 'en-US', + translations: { + errors: { + userNotFound: 'Custom override message', + }, + }, + }; + + const config = { + translations: [customEnUs], + }; + + const result = config.translations.reduce( + (acc, t) => ({ + ...acc, + [t.locale]: t.translations, + }), + { [english.locale]: english.translations } + ); + + expect(result['en-US'].errors.userNotFound).toBe('Custom override message'); + }); });