feat(i18n): implement internationalization framework and update UI components for language support

This commit is contained in:
HouYunFei
2026-08-05 14:08:03 +08:00
parent 9bccd0ff1a
commit 0f6809251a
116 changed files with 3269 additions and 1870 deletions
+7 -5
View File
@@ -3,6 +3,8 @@ import { create } from "zustand";
import { persist } from "zustand/middleware";
import { nanoid } from "nanoid";
import i18n from "@/i18n";
export type ApiCallFormat = "openai" | "gemini" | "ark";
export type ModelCapability = "image" | "video" | "text" | "audio";
export type ReasoningEffort = "auto" | "low" | "medium" | "high" | "xhigh";
@@ -74,7 +76,7 @@ export const defaultConfig: AiConfig = {
channels: [
{
id: "default",
name: "默认渠道",
name: i18n.t("config.channels.defaultName"),
baseUrl: OPENAI_BASE_URL,
apiKey: "",
apiFormat: "openai",
@@ -276,7 +278,7 @@ export function createModelChannel(channel?: Partial<ModelChannel>): ModelChanne
const apiFormat = normalizeApiFormat(channel?.apiFormat);
return {
id: channel?.id?.trim() || nanoid(),
name: channel?.name?.trim() || "新渠道",
name: channel?.name?.trim() || i18n.t("config.channels.newName"),
baseUrl: channel?.baseUrl?.trim() || defaultBaseUrlForApiFormat(apiFormat),
apiKey: channel?.apiKey || "",
apiFormat,
@@ -329,7 +331,7 @@ export function resolveModelChannel(config: AiConfig, value: string) {
const decoded = decodeChannelModel(value);
const model = decoded?.model || value;
const matched = decoded ? config.channels.find((channel) => channel.id === decoded.channelId) : config.channels.find((channel) => channel.models.some((item) => item.name === model));
return matched || config.channels[0] || createModelChannel({ id: "default", name: "默认渠道", baseUrl: config.baseUrl, apiKey: config.apiKey, apiFormat: config.apiFormat, models: config.models.map(modelOptionName).map((name) => ({ name, capability: guessCapability(name) })) });
return matched || config.channels[0] || createModelChannel({ id: "default", name: i18n.t("config.channels.defaultName"), baseUrl: config.baseUrl, apiKey: config.apiKey, apiFormat: config.apiFormat, models: config.models.map(modelOptionName).map((name) => ({ name, capability: guessCapability(name) })) });
}
export function resolveModelRequestConfig(config: AiConfig, value: string) {
@@ -349,7 +351,7 @@ function normalizeChannels(config: AiConfig) {
createModelChannel({
...channel,
id: channel.id || (index === 0 ? "default" : `channel-${index + 1}`),
name: channel.name || (index === 0 ? "默认渠道" : `渠道 ${index + 1}`),
name: channel.name || (index === 0 ? i18n.t("config.channels.defaultName") : i18n.t("config.channels.indexedName", { index: index + 1 })),
models: normalizeChannelModels(channel.models),
}),
);
@@ -357,7 +359,7 @@ function normalizeChannels(config: AiConfig) {
channels.push(
createModelChannel({
id: "default",
name: "默认渠道",
name: i18n.t("config.channels.defaultName"),
baseUrl: config.baseUrl || defaultConfig.baseUrl,
apiKey: config.apiKey || "",
apiFormat: config.apiFormat || defaultConfig.apiFormat,