Normalize language code comparisons

Due to using the browsers' preferred languages by default, there was a possibility that the preferred language codes did not match any extension/source language, which lead to broken filtering.

While this happened, it was also possible that the preferred languages still matched properly to a language in the language filter, which caused confusion.
This was the case e.g., for "en-GB" or "en-US"
This commit is contained in:
schroda
2025-04-24 13:38:05 +02:00
parent 01856b9847
commit 4c04e1d17c
3 changed files with 31 additions and 6 deletions

View File

@@ -75,6 +75,10 @@ export const toUniqueLanguageCodes = (codes: string[]): string[] => {
.map(([, languagesOfIsoCode]) => languagesOfIsoCode![0].orgCode);
};
export const toComparableLanguage = (code: string): string => getLanguage(code).isoCode;
export const toComparableLanguages = (codes: string[]): string[] => codes.map(toComparableLanguage);
function defaultNativeLang(): readonly string[] {
const preferredLanguages = toUniqueLanguageCodes([...navigator.languages]);