feat: add more custom apis

This commit is contained in:
Gabe Yuan
2024-04-01 11:50:29 +08:00
parent dc3c510d57
commit 60d788288d
2 changed files with 20 additions and 7 deletions

View File

@@ -102,6 +102,10 @@ export const OPT_TRANS_OPENAI = "OpenAI";
export const OPT_TRANS_GEMINI = "Gemini"; export const OPT_TRANS_GEMINI = "Gemini";
export const OPT_TRANS_CLOUDFLAREAI = "CloudflareAI"; export const OPT_TRANS_CLOUDFLAREAI = "CloudflareAI";
export const OPT_TRANS_CUSTOMIZE = "Custom"; export const OPT_TRANS_CUSTOMIZE = "Custom";
export const OPT_TRANS_CUSTOMIZE_2 = "Custom2";
export const OPT_TRANS_CUSTOMIZE_3 = "Custom3";
export const OPT_TRANS_CUSTOMIZE_4 = "Custom4";
export const OPT_TRANS_CUSTOMIZE_5 = "Custom5";
export const OPT_TRANS_ALL = [ export const OPT_TRANS_ALL = [
OPT_TRANS_GOOGLE, OPT_TRANS_GOOGLE,
OPT_TRANS_MICROSOFT, OPT_TRANS_MICROSOFT,
@@ -114,6 +118,10 @@ export const OPT_TRANS_ALL = [
OPT_TRANS_GEMINI, OPT_TRANS_GEMINI,
OPT_TRANS_CLOUDFLAREAI, OPT_TRANS_CLOUDFLAREAI,
OPT_TRANS_CUSTOMIZE, OPT_TRANS_CUSTOMIZE,
OPT_TRANS_CUSTOMIZE_2,
OPT_TRANS_CUSTOMIZE_3,
OPT_TRANS_CUSTOMIZE_4,
OPT_TRANS_CUSTOMIZE_5,
]; ];
export const OPT_LANGS_TO = [ export const OPT_LANGS_TO = [
@@ -400,6 +408,12 @@ export const DEFAULT_SUBRULES_LIST = [
]; ];
// 翻译接口 // 翻译接口
const defaultCustomApi = {
url: "",
key: "",
fetchLimit: DEFAULT_FETCH_LIMIT,
fetchInterval: DEFAULT_FETCH_INTERVAL,
};
export const DEFAULT_TRANS_APIS = { export const DEFAULT_TRANS_APIS = {
[OPT_TRANS_GOOGLE]: { [OPT_TRANS_GOOGLE]: {
url: "https://translate.googleapis.com/translate_a/single", url: "https://translate.googleapis.com/translate_a/single",
@@ -457,12 +471,11 @@ export const DEFAULT_TRANS_APIS = {
fetchLimit: 1, fetchLimit: 1,
fetchInterval: 500, fetchInterval: 500,
}, },
[OPT_TRANS_CUSTOMIZE]: { [OPT_TRANS_CUSTOMIZE]: defaultCustomApi,
url: "", [OPT_TRANS_CUSTOMIZE_2]: defaultCustomApi,
key: "", [OPT_TRANS_CUSTOMIZE_3]: defaultCustomApi,
fetchLimit: DEFAULT_FETCH_LIMIT, [OPT_TRANS_CUSTOMIZE_4]: defaultCustomApi,
fetchInterval: DEFAULT_FETCH_INTERVAL, [OPT_TRANS_CUSTOMIZE_5]: defaultCustomApi,
},
}; };
// 默认快捷键 // 默认快捷键

View File

@@ -208,7 +208,7 @@ function ApiFields({ translator }) {
</Button> </Button>
</Stack> </Stack>
{translator === OPT_TRANS_CUSTOMIZE && ( {translator.startsWith(OPT_TRANS_CUSTOMIZE) && (
<pre>{i18n("custom_api_help")}</pre> <pre>{i18n("custom_api_help")}</pre>
)} )}
</Stack> </Stack>