mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-08 16:57:14 +01:00
feat(i18n): enhance language detection from browser preferences and add tests
This commit is contained in:
1 parent
e117ab93bd
commit
d7e06ce361
2 files changed
+144
-1
No files matched your search
+15
-1
@@ -73,7 +73,21 @@ export const getLanguageFromUrl = (): SupportedLanguage => {
|
||||
return storedLang as SupportedLanguage;
|
||||
}
|
||||
|
||||
const envLang = import.meta.env.VITE_DEFAULT_LANGUAGE;
|
||||
// Check browser language preferences
|
||||
if (typeof navigator !== 'undefined' && navigator.languages) {
|
||||
for (const lang of navigator.languages) {
|
||||
if (supportedLanguages.includes(lang as SupportedLanguage)) {
|
||||
return lang as SupportedLanguage;
|
||||
}
|
||||
|
||||
const primaryLang = lang.split('-')[0];
|
||||
if (supportedLanguages.includes(primaryLang as SupportedLanguage)) {
|
||||
return primaryLang as SupportedLanguage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const envLang = import.meta.env?.VITE_DEFAULT_LANGUAGE;
|
||||
if (envLang && supportedLanguages.includes(envLang as SupportedLanguage)) {
|
||||
return envLang as SupportedLanguage;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user