mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(web): use browser language by default (#10849)
This commit is contained in:
parent
6629bf50ae
commit
6030349a6f
4 changed files with 55 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { langs } from '$lib/constants';
|
||||
import messages from '$lib/i18n/en.json';
|
||||
import { getClosestAvailableLocale } from '$lib/utils/i18n';
|
||||
import { exec as execCallback } from 'node:child_process';
|
||||
import { readFileSync, readdirSync } from 'node:fs';
|
||||
import { promisify } from 'node:util';
|
||||
|
|
@ -52,4 +53,30 @@ describe('i18n', () => {
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('getClosestAvailableLocale', () => {
|
||||
const allLocales = ['ar', 'bg', 'en', 'en-US', 'en-DE', 'zh-Hans', 'zh-Hans-HK'];
|
||||
|
||||
it('returns undefined on mismatch', () => {
|
||||
expect(getClosestAvailableLocale([], allLocales)).toBeUndefined();
|
||||
expect(getClosestAvailableLocale(['invalid'], allLocales)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns the first matching locale', () => {
|
||||
expect(getClosestAvailableLocale(['invalid', 'ar', 'bg'], allLocales)).toBe('ar');
|
||||
expect(getClosestAvailableLocale(['bg'], allLocales)).toBe('bg');
|
||||
expect(getClosestAvailableLocale(['bg', 'invalid', 'ar'], allLocales)).toBe('bg');
|
||||
});
|
||||
|
||||
it('returns the locale for a less specific match', () => {
|
||||
expect(getClosestAvailableLocale(['ar-AE'], allLocales)).toBe('ar-AE');
|
||||
expect(getClosestAvailableLocale(['ar-AE', 'en'], allLocales)).toBe('ar-AE');
|
||||
expect(getClosestAvailableLocale(['zh-Hans-HK', 'zh-Hans'], allLocales)).toBe('zh-Hans-HK');
|
||||
});
|
||||
|
||||
it('ignores the locale for a more specific match', () => {
|
||||
expect(getClosestAvailableLocale(['zh'], allLocales)).toBeUndefined();
|
||||
expect(getClosestAvailableLocale(['de', 'zh', 'en-US'], allLocales)).toBe('en-US');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue