Commit 2aecd7d0 authored by Jonathan Rohde's avatar Jonathan Rohde
Browse files

Merge branch 'refs/heads/dev' into feat/sqlalchemy-instead-of-peewee

# Conflicts:
#	backend/requirements.txt
parents 5391f4c1 f3c1ff9e
......@@ -261,8 +261,8 @@
"File": "文件",
"File Mode": "文件模式",
"File not found.": "文件未找到。",
"Filter is now globally disabled": "",
"Filter is now globally enabled": "",
"Filter is now globally disabled": "过滤器已全局禁用",
"Filter is now globally enabled": "过滤器已全局启用",
"Filters": "过滤器",
"Fingerprint spoofing detected: Unable to use initials as avatar. Defaulting to default profile image.": "检测到指纹伪造:无法使用姓名缩写作为头像。默认使用默认个人形象。",
"Fluidly stream large external response chunks": "流畅地传输外部大型响应块数据",
......@@ -281,7 +281,7 @@
"Generate Image": "生成图像",
"Generating search query": "生成搜索查询",
"Generation Info": "生成信息",
"Global": "",
"Global": "全局",
"Good Response": "点赞此回答",
"Google PSE API Key": "Google PSE API 密钥",
"Google PSE Engine Id": "Google PSE 引擎 ID",
......
......@@ -525,7 +525,7 @@ export const extractSentences = (text) => {
});
// Split the modified text into sentences based on common punctuation marks, avoiding these blocks
let sentences = text.split(/(?<=[.!?])\s+/);
let sentences = text.match(/[^.?!]+[.!?]+[\])'"`’”]*|.+/g);
// Restore code blocks and process sentences
sentences = sentences.map((sentence) => {
......@@ -746,3 +746,15 @@ export const extractFrontmatter = (content) => {
return frontmatter;
};
// Function to determine the best matching language
export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, defaultLocale) => {
const languages = supportedLanguages.map((lang) => lang.code);
const match = preferredLanguages
.map((prefLang) => languages.find((lang) => lang.startsWith(prefLang)))
.find(Boolean);
console.log(languages, preferredLanguages, match, defaultLocale);
return match || defaultLocale;
};
......@@ -31,6 +31,7 @@
import { WEBUI_BASE_URL, WEBUI_HOSTNAME } from '$lib/constants';
import i18n, { initI18n, getLanguages } from '$lib/i18n';
import { bestMatchingLanguage } from '$lib/utils';
setContext('i18n', i18n);
......@@ -91,13 +92,17 @@
// Initialize i18n even if we didn't get a backend config,
// so `/error` can show something that's not `undefined`.
initI18n();
if (!localStorage.locale) {
const languages = await getLanguages();
const browserLanguage = navigator.languages
? navigator.languages[0]
: navigator.language || navigator.userLanguage;
initI18n(languages.includes(browserLanguage) ? browserLanguage : backendConfig?.default_locale);
const browserLanguages = navigator.languages
? navigator.languages
: [navigator.language || navigator.userLanguage];
const lang = backendConfig.default_locale
? backendConfig.default_locale
: bestMatchingLanguage(languages, browserLanguages, 'en-US');
$i18n.changeLanguage(lang);
}
if (backendConfig) {
// Save Backend Status to Store
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment