Skip to content

Commit

Permalink
fix: i18n default language resolution (#12786)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblanc authored Jan 2, 2024
1 parent bedbdbd commit 05d73ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/core/__tests__/I18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ describe('I18n test', () => {
});

describe('get test', () => {
let languageGetterSpy;

beforeEach(() => {
languageGetterSpy = jest.spyOn(window.navigator, 'language', 'get')
});

test('no language', () => {
const i18n = new I18n();

Expand Down Expand Up @@ -59,6 +65,20 @@ describe('I18n test', () => {

spyon.mockClear();
});

test('sets default language', () => {
languageGetterSpy.mockReturnValue('fr')

const i18n = new I18n();

i18n.putVocabularies({
'fr': {
'Sign In': 'Se connecter',
}
});

expect(i18n.get('Sign In')).toBe('Se connecter');
});
});

describe('getByLanguage test', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/I18n/I18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export class I18n {
* @param {String} defVal - Default value
*/
get(key: string, defVal: string | undefined = undefined) {
this.setDefaultLanguage();

if (!this._lang) {
return typeof defVal !== 'undefined' ? defVal : key;
}
Expand Down

0 comments on commit 05d73ab

Please sign in to comment.