Spellcheck: Use full locale, otherwise all which match base

This commit is contained in:
Scott Nonnenberg 2022-06-27 13:44:13 -07:00 committed by GitHub
parent 5d570e2d67
commit 054e443071
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 8 deletions

View file

@ -15,18 +15,16 @@ export function getLanguages(
userLocale: string, userLocale: string,
availableLocales: ReadonlyArray<string> availableLocales: ReadonlyArray<string>
): Array<string> { ): Array<string> {
const baseLocale = userLocale.split('-')[0]; // First attempt to find the exact locale
// Attempt to find the exact locale const candidateLocales = uniq([userLocale, userLocale]).filter(l =>
const candidateLocales = uniq([userLocale, baseLocale]).filter(l =>
availableLocales.includes(l) availableLocales.includes(l)
); );
if (candidateLocales.length > 0) { if (candidateLocales.length > 0) {
return candidateLocales; return candidateLocales;
} }
// If no languages were found then just return all locales that start with the // If no languages were found then return all locales that start with the base
// base const baseLocale = userLocale.split('-')[0];
return uniq(availableLocales.filter(l => l.startsWith(baseLocale))); return uniq(availableLocales.filter(l => l.startsWith(baseLocale)));
} }

View file

@ -10,7 +10,6 @@ describe('SpellCheck', () => {
it('works with locale and base available', () => { it('works with locale and base available', () => {
assert.deepEqual(getLanguages('en-US', ['en-US', 'en-CA', 'en']), [ assert.deepEqual(getLanguages('en-US', ['en-US', 'en-CA', 'en']), [
'en-US', 'en-US',
'en',
]); ]);
}); });
@ -22,7 +21,7 @@ describe('SpellCheck', () => {
}); });
it('works with only base locale available', () => { it('works with only base locale available', () => {
assert.deepEqual(getLanguages('en-US', ['en', 'en-CA']), ['en']); assert.deepEqual(getLanguages('en-US', ['en', 'en-CA']), ['en', 'en-CA']);
}); });
it('works with only full locale available', () => { it('works with only full locale available', () => {