i18n
This commit is contained in:
51
src/translate/index.tsx
Normal file
51
src/translate/index.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import { createContext } from "preact";
|
||||
import MAP_zh_CN from "./zh_CN";
|
||||
|
||||
interface LangOption {
|
||||
name: string;
|
||||
langMap: Record<string, string>;
|
||||
matches: string[];
|
||||
}
|
||||
|
||||
const LANG_OPTIONS: Record<string, LangOption> = {
|
||||
"en-US": {
|
||||
name: "English",
|
||||
langMap: {},
|
||||
matches: ["en-US", "en"],
|
||||
},
|
||||
"zh-CN": {
|
||||
name: "中文(简体)",
|
||||
langMap: MAP_zh_CN,
|
||||
matches: ["zh-CN", "zh"],
|
||||
},
|
||||
};
|
||||
|
||||
const langCodeContext = createContext("en-US");
|
||||
|
||||
function tr(text: string, langCode: "en-US" | "zh-CN") {
|
||||
const option = LANG_OPTIONS[langCode];
|
||||
if (option === undefined) {
|
||||
return text;
|
||||
}
|
||||
const langMap = LANG_OPTIONS[langCode].langMap;
|
||||
|
||||
const translatedText = langMap[text.toLowerCase()];
|
||||
if (translatedText === undefined) {
|
||||
return text;
|
||||
}
|
||||
|
||||
return translatedText;
|
||||
}
|
||||
|
||||
function Tr(text: string) {
|
||||
return (
|
||||
<langCodeContext.Consumer>
|
||||
{/* @ts-ignore */}
|
||||
{({ langCode }) => {
|
||||
return tr(text, langCode);
|
||||
}}
|
||||
</langCodeContext.Consumer>
|
||||
);
|
||||
}
|
||||
|
||||
export { tr, Tr, LANG_OPTIONS, langCodeContext };
|
||||
58
src/translate/zh_CN.ts
Normal file
58
src/translate/zh_CN.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
const LANG_MAP: Record<string, string> = {
|
||||
settings: "设置",
|
||||
model: "模型",
|
||||
"copy setting link": "复制设置链接",
|
||||
"are you sure to clear all history?": "确定要清除所有历史记录吗?",
|
||||
"clear history": "清除历史记录",
|
||||
new: "新",
|
||||
del: "删",
|
||||
cut: "遗忘",
|
||||
"please click above to set": "请点击上方进行设置",
|
||||
cost: "消费",
|
||||
stream: "流式返回",
|
||||
fetch: "一次获取",
|
||||
"saved api templates": "已保存的 API 模板",
|
||||
"saved prompt templates": "已保存的提示模板",
|
||||
"no chat history here": "暂无历史对话记录",
|
||||
"click above to change the settings of this chat":
|
||||
"点击上方更改此对话的参数(请勿泄漏)",
|
||||
"click the NEW to create a new chat": "点击左上角 NEW 新建对话",
|
||||
"all chat history and settings are stored in the local browser":
|
||||
"所有历史对话与参数储存在浏览器本地",
|
||||
"documents and source code are avaliable here":
|
||||
"详细文档与源代码可在此处获取",
|
||||
"generating...": "生成中,请保持网络稳定...",
|
||||
"re-generate": "重新生成",
|
||||
completion: "补全",
|
||||
"generated by": "生成模型: ",
|
||||
"info: chat history is too long, forget messages":
|
||||
"提示:对话历史过长,遗忘消息数量",
|
||||
"warning: current chatstore version": "警告:当前会话版本",
|
||||
retry: "重试",
|
||||
send: "发送",
|
||||
assistant: "AI消息",
|
||||
user: "用户消息",
|
||||
close: "关闭",
|
||||
"message copied to clipboard": "消息已复制到剪贴板",
|
||||
"total cost in this session": "本次会话总消费",
|
||||
"accumulated cost in all sessions": "所有会话总消费",
|
||||
export: "导出",
|
||||
"give this template a name:": "给此模板命名:",
|
||||
"no template name specified": "未指定模板名称",
|
||||
"as template": "保存为会话模板",
|
||||
"as api template": "保存为 API 模板",
|
||||
"this will overwrite the current chat history! continue?":
|
||||
"此操作将覆盖当前会话历史!继续?",
|
||||
"please select a json file": "请选择一个 JSON 文件",
|
||||
"empty file": "警告: 空文件",
|
||||
"this is not an exported chatgpt-api-web chatstore file. the key 'chatgpt_api_web_version' is missing!":
|
||||
"此文件不是 chatgpt-api-web 导出的会话文件,缺少 chatgpt_api_web_version 键值!",
|
||||
"import error on parsing json": "JSON 解析错误",
|
||||
version: "版本",
|
||||
"copied link:": "已复制链接:",
|
||||
reset: "重置",
|
||||
example: "示例",
|
||||
render: "渲染",
|
||||
};
|
||||
|
||||
export default LANG_MAP;
|
||||
Reference in New Issue
Block a user