Skip to content

fix(core): translation locales now de-duped when initialising #1161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v7-alpha
Choose a base branch
from
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
21 changes: 12 additions & 9 deletions packages/firebaseui-core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions packages/firebaseui-core/tests/unit/translations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});