Modify language identification in locale handling
The update changes the way locales are checked against the list of accepted languages. Now, instead the full locale, only the language segment is considered when determining if the locale is accepted. Additionally, a check in 'getPreferredLanguageFromBrowser' was added to ensure 'acceptLanguage' is not undefined before attempting to parse it.
This commit is contained in:
@@ -73,9 +73,15 @@ export function parseAcceptLanguageHeader(
|
||||
// Ignore wildcard '*' if 'ignoreWildcard' is true
|
||||
if (locale === '*' && ignoreWildcard) return [];
|
||||
|
||||
const languageSegment = locale.split('-')[0];
|
||||
|
||||
if (!languageSegment) return [];
|
||||
|
||||
// Return the locale if it's included in the accepted languages
|
||||
try {
|
||||
return acceptedLanguages.includes(locale) ? [locale] : [];
|
||||
return acceptedLanguages.includes(languageSegment)
|
||||
? [languageSegment]
|
||||
: [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user