Skip to content

Commit

Permalink
Spellcheck: Use full locale, otherwise all which match base
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Jun 27, 2022
1 parent 5d570e2 commit 054e443
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
10 changes: 4 additions & 6 deletions app/spell_check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ export function getLanguages(
userLocale: string,
availableLocales: ReadonlyArray<string>
): Array<string> {
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)));
}

Expand Down
3 changes: 1 addition & 2 deletions ts/test-node/app/spell_check_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
});

Expand All @@ -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', () => {
Expand Down

0 comments on commit 054e443

Please sign in to comment.