mirror of
https://github.com/open-webui/open-webui
synced 2025-01-18 00:30:51 +00:00
refac: language detection
This commit is contained in:
parent
4b0c422ec5
commit
5ee7da54a1
@ -750,6 +750,11 @@ export const extractFrontmatter = (content) => {
|
|||||||
// Function to determine the best matching language
|
// Function to determine the best matching language
|
||||||
export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, defaultLocale) => {
|
export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, defaultLocale) => {
|
||||||
const languages = supportedLanguages.map((lang) => lang.code);
|
const languages = supportedLanguages.map((lang) => lang.code);
|
||||||
const match = preferredLanguages.find((lang) => languages.includes(lang));
|
|
||||||
|
const match = preferredLanguages
|
||||||
|
.map((prefLang) => languages.find((lang) => lang.startsWith(prefLang)))
|
||||||
|
.find(Boolean);
|
||||||
|
|
||||||
|
console.log(languages, preferredLanguages, match, defaultLocale);
|
||||||
return match || defaultLocale;
|
return match || defaultLocale;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user