Browse Source

Merge pull request #3546 from open-webui/dev

refac: language detection
Timothy Jaeryang Baek 10 months ago
parent
commit
66182bac75
2 changed files with 6 additions and 2 deletions
  1. 0 1
      CHANGELOG.md
  2. 6 1
      src/lib/utils/index.ts

+ 0 - 1
CHANGELOG.md

@@ -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

+ 6 - 1
src/lib/utils/index.ts

@@ -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;
 };