Merge pull request #3546 from open-webui/dev

refac: language detection
This commit is contained in:
Timothy Jaeryang Baek 2024-06-29 20:41:32 -07:00 committed by GitHub
commit 66182bac75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -5,7 +5,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.3.7] - 2024-06-29
### Added

View File

@ -750,6 +750,11 @@ export const extractFrontmatter = (content) => {
// Function to determine the best matching language
export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, defaultLocale) => {
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;
};