mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-17 03:27:02 +08:00
- 修复内存泄漏问题,该可能导致内存异常占用 - 支持俄语增加翻译范围 - 修复qwen-3.8-max中断问题(mimo也应该属于同一类问题) - 修复claude模型可能无法识别图片问题 @GGHansome - 支持自定义Openai端点 @Sxuan-Coder - WebSearch 接入百度搜索,DuckDuckGo 作为兜底 @杨超 - 修复一些兼容性问题 @kael-odin - 修复window上一些表现问题 @philau2512 🔔 如何让AI自动拉模型配置? (以下为提示词,把地址和密钥换为你的) 我的模型配置在 ~/.cursor-local-assistant-v2/config.yaml,我的API地址是:https://xxx 密钥是xxx,帮我拉所有模型配置进去,不要影响已有模型,根据models标准接口拉取。
192 lines
4.9 KiB
JavaScript
192 lines
4.9 KiB
JavaScript
import { computed, ref } from "vue";
|
|
import { Events } from "@wailsio/runtime";
|
|
import {
|
|
DEFAULT_LOCALE,
|
|
LOCALE_OPTIONS,
|
|
LOCALE_STORAGE_KEY,
|
|
LOCALE_STORAGE_SOURCE_KEY,
|
|
SOURCE_LOCALE,
|
|
SUPPORTED_LOCALES,
|
|
} from "@/i18n/config";
|
|
import zhCNMessages from "@/i18n/locales/zh-CN.json";
|
|
import enUSMessages from "@/i18n/locales/en-US.json";
|
|
import jaJPMessages from "@/i18n/locales/ja-JP.json";
|
|
import ruRUMessages from "@/i18n/locales/ru-RU.json";
|
|
|
|
const localeMessages = {
|
|
"zh-CN": zhCNMessages,
|
|
"en-US": enUSMessages,
|
|
"ja-JP": jaJPMessages,
|
|
"ru-RU": ruRUMessages,
|
|
};
|
|
|
|
const languageLocaleMap = {
|
|
zh: "zh-CN",
|
|
en: "en-US",
|
|
ja: "ja-JP",
|
|
ru: "ru-RU",
|
|
};
|
|
|
|
function isSupportedLocale(locale) {
|
|
return SUPPORTED_LOCALES.includes(locale);
|
|
}
|
|
|
|
function matchSupportedLocale(locale) {
|
|
const normalized = String(locale || "").trim().replace(/_/g, "-");
|
|
if (!normalized) {
|
|
return "";
|
|
}
|
|
|
|
const lowered = normalized.toLowerCase();
|
|
const exactMatch = SUPPORTED_LOCALES.find((supportedLocale) => supportedLocale.toLowerCase() === lowered);
|
|
if (exactMatch) {
|
|
return exactMatch;
|
|
}
|
|
|
|
const primaryLanguage = lowered.split("-")[0];
|
|
return languageLocaleMap[primaryLanguage] || "";
|
|
}
|
|
|
|
function getSystemLocaleCandidates() {
|
|
const candidates = [];
|
|
|
|
if (typeof navigator !== "undefined") {
|
|
if (Array.isArray(navigator.languages)) {
|
|
candidates.push(...navigator.languages);
|
|
}
|
|
candidates.push(navigator.language);
|
|
}
|
|
|
|
if (typeof Intl !== "undefined" && typeof Intl.DateTimeFormat === "function") {
|
|
candidates.push(Intl.DateTimeFormat().resolvedOptions()?.locale);
|
|
}
|
|
|
|
return candidates;
|
|
}
|
|
|
|
function resolveSystemLocale() {
|
|
for (const candidate of getSystemLocaleCandidates()) {
|
|
const matchedLocale = matchSupportedLocale(candidate);
|
|
if (matchedLocale) {
|
|
return matchedLocale;
|
|
}
|
|
}
|
|
|
|
return DEFAULT_LOCALE;
|
|
}
|
|
|
|
function resolveInitialLocale() {
|
|
if (typeof window === "undefined" || typeof window.localStorage === "undefined") {
|
|
return resolveSystemLocale();
|
|
}
|
|
|
|
const storedLocale = window.localStorage.getItem(LOCALE_STORAGE_KEY);
|
|
const storedSource = window.localStorage.getItem(LOCALE_STORAGE_SOURCE_KEY);
|
|
if (storedSource === "manual") {
|
|
return matchSupportedLocale(storedLocale) || resolveSystemLocale();
|
|
}
|
|
|
|
window.localStorage.removeItem(LOCALE_STORAGE_KEY);
|
|
window.localStorage.removeItem(LOCALE_STORAGE_SOURCE_KEY);
|
|
return resolveSystemLocale();
|
|
}
|
|
|
|
function applyLocaleToDocument(locale) {
|
|
if (typeof document !== "undefined") {
|
|
document.documentElement.lang = locale;
|
|
}
|
|
}
|
|
|
|
function persistManualLocale(locale) {
|
|
if (typeof window === "undefined" || typeof window.localStorage === "undefined") {
|
|
return;
|
|
}
|
|
|
|
window.localStorage.setItem(LOCALE_STORAGE_KEY, locale);
|
|
window.localStorage.setItem(LOCALE_STORAGE_SOURCE_KEY, "manual");
|
|
}
|
|
|
|
function resolveMessage(id, fallback) {
|
|
const activeMessages = localeMessages[currentLocale.value] || {};
|
|
const sourceMessages = localeMessages[SOURCE_LOCALE] || {};
|
|
return activeMessages[id] || sourceMessages[id] || fallback || "";
|
|
}
|
|
|
|
function interpolateMessage(template, args = []) {
|
|
return template.replace(/\{(\d+)\}/g, (_match, index) => {
|
|
const value = args[Number(index)];
|
|
return value == null ? "" : String(value);
|
|
});
|
|
}
|
|
|
|
class LocalizedText extends String {
|
|
constructor(id, fallback, args = null) {
|
|
super(fallback);
|
|
this.id = id;
|
|
this.fallback = fallback;
|
|
this.args = args;
|
|
}
|
|
|
|
toString() {
|
|
const text = resolveMessage(this.id, this.fallback);
|
|
return Array.isArray(this.args) ? interpolateMessage(text, this.args) : text;
|
|
}
|
|
|
|
valueOf() {
|
|
return this.toString();
|
|
}
|
|
|
|
toJSON() {
|
|
return this.toString();
|
|
}
|
|
|
|
[Symbol.toPrimitive]() {
|
|
return this.toString();
|
|
}
|
|
}
|
|
|
|
const currentLocale = ref(resolveInitialLocale());
|
|
applyLocaleToDocument(currentLocale.value);
|
|
Events.Emit("locale:changed", currentLocale.value);
|
|
|
|
const localizedCache = new Map();
|
|
|
|
export function getLocale() {
|
|
return currentLocale.value;
|
|
}
|
|
|
|
export function setLocale(locale) {
|
|
const nextLocale = matchSupportedLocale(locale) || DEFAULT_LOCALE;
|
|
currentLocale.value = nextLocale;
|
|
persistManualLocale(nextLocale);
|
|
applyLocaleToDocument(nextLocale);
|
|
Events.Emit("locale:changed", nextLocale);
|
|
return nextLocale;
|
|
}
|
|
|
|
export function useLocale() {
|
|
return {
|
|
locale: currentLocale,
|
|
localeOptions: LOCALE_OPTIONS,
|
|
currentLocale: computed(() => currentLocale.value),
|
|
setLocale,
|
|
};
|
|
}
|
|
|
|
export function localized(id, fallback) {
|
|
const cacheKey = `${id}:${fallback}`;
|
|
if (!localizedCache.has(cacheKey)) {
|
|
localizedCache.set(cacheKey, new LocalizedText(id, fallback));
|
|
}
|
|
return localizedCache.get(cacheKey);
|
|
}
|
|
|
|
export function localizedTemplate(id, fallback, args = []) {
|
|
return new LocalizedText(id, fallback, args);
|
|
}
|
|
|
|
export function installI18nRuntime(app) {
|
|
app.config.globalProperties.$ls = localized;
|
|
app.config.globalProperties.$lt = localizedTemplate;
|
|
}
|