Add i18n support #5
@ -1,9 +1,15 @@
|
||||
const supportedLocales = ["sv", "en"];
|
||||
|
||||
export function getDefaultLocale(): string {
|
||||
const lang = navigator.language.split("-")[0]; // "en-US" -> "en"
|
||||
const userPreferredLangs = navigator.languages.map(
|
||||
|
stne3960 marked this conversation as resolved
Outdated
|
||||
(lang) => lang.split("-")[0],
|
||||
);
|
||||
|
||||
for (const lang of userPreferredLangs) {
|
||||
if (supportedLocales.includes(lang)) {
|
||||
return lang;
|
||||
}
|
||||
return "sv"; // fallback to Swedish
|
||||
}
|
||||
|
||||
return "en"; // fallback to English
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user
Should maybe iterate over
navigator.languagesinstead to find the most preferred locale? If a user sends "Accept-Language: de-DE, en-US, sv-SE" they will get Swedish instead of English since German isn't available.Also should we maybe default to English if no available language is found instead of Swedish?
I agree that we should interate over
navigator.languagesinstead.Regarding defaulting to english if no language is found, very good question. We are Swedish public agency, most outward facing systems default to Swedish, but on the other hand, if they don't have Swedish as an accepted language, there's probably a high likelyhood that they are non-Swedish speakers. I think there's a strong case here to default to English.
Based on that I'd say defaulting to English makes sense and adhering to the "Accept-Language" header is just nice for users.