Skip to content

Commit

Permalink
Don't always duplicate default locale in decentLocaleMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
piemonkey committed Apr 29, 2024
1 parent 33b0b76 commit 7538e80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-cups-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frontend-gelinkt-notuleren": patch
---

Remove duplication of supported locales passed to ember-intl
20 changes: 8 additions & 12 deletions app/utils/intl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,18 @@ export function decentLocaleMatch(
matchUserLocaleToSupportedLocale(userLocale, supportedLocales),
);

const lowerCaseDefaultLocale = defaultLocale.toLowerCase();

const deduplicatedSupportedLocales = new Set([
...supportedLocalesThatUserPrefers.map(
(locale) => locale && locale.toLowerCase(),
),
defaultLocale.toLowerCase(),
...supportedLocalesThatUserPrefers
.map((locale) => locale && locale.toLowerCase())
.filter((locale) => typeof locale === 'string'),
lowerCaseDefaultLocale,
]);

const definedSupportedLocales = [...deduplicatedSupportedLocales].filter(
(locale) => typeof locale === 'string',
);

const lowerCaseDefaultLocale = defaultLocale.toLowerCase();

if (definedSupportedLocales.length < 1) {
if (deduplicatedSupportedLocales.size < 1) {
return [lowerCaseDefaultLocale];
}

return [...definedSupportedLocales, lowerCaseDefaultLocale];
return [...deduplicatedSupportedLocales];
}

0 comments on commit 7538e80

Please sign in to comment.