From 054e443071e7fccd610203b74ce73dbcfedbfb02 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 27 Jun 2022 13:44:13 -0700 Subject: [PATCH] Spellcheck: Use full locale, otherwise all which match base --- app/spell_check.ts | 10 ++++------ ts/test-node/app/spell_check_test.ts | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/spell_check.ts b/app/spell_check.ts index 59a89dce2..ce7c9c4a8 100644 --- a/app/spell_check.ts +++ b/app/spell_check.ts @@ -15,18 +15,16 @@ export function getLanguages( userLocale: string, availableLocales: ReadonlyArray ): Array { - const baseLocale = userLocale.split('-')[0]; - // Attempt to find the exact locale - const candidateLocales = uniq([userLocale, baseLocale]).filter(l => + // First attempt to find the exact locale + const candidateLocales = uniq([userLocale, userLocale]).filter(l => availableLocales.includes(l) ); - if (candidateLocales.length > 0) { return candidateLocales; } - // If no languages were found then just return all locales that start with the - // base + // If no languages were found then return all locales that start with the base + const baseLocale = userLocale.split('-')[0]; return uniq(availableLocales.filter(l => l.startsWith(baseLocale))); } diff --git a/ts/test-node/app/spell_check_test.ts b/ts/test-node/app/spell_check_test.ts index 4f9d1c700..e29dc360c 100644 --- a/ts/test-node/app/spell_check_test.ts +++ b/ts/test-node/app/spell_check_test.ts @@ -10,7 +10,6 @@ describe('SpellCheck', () => { it('works with locale and base available', () => { assert.deepEqual(getLanguages('en-US', ['en-US', 'en-CA', 'en']), [ 'en-US', - 'en', ]); }); @@ -22,7 +21,7 @@ describe('SpellCheck', () => { }); 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', () => {