From b206e3e95d65372eae8c4300be1d034728b10919 Mon Sep 17 00:00:00 2001 From: rockbenben Date: Mon, 18 Mar 2024 21:59:36 +0800 Subject: [PATCH] refactor: change translate component to use constant module --- src/app/components/transalteConstants.tsx | 26 +++++++++++++++++++++ src/app/json-translate/client.tsx | 28 +---------------------- 2 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 src/app/components/transalteConstants.tsx diff --git a/src/app/components/transalteConstants.tsx b/src/app/components/transalteConstants.tsx new file mode 100644 index 0000000..9a3784c --- /dev/null +++ b/src/app/components/transalteConstants.tsx @@ -0,0 +1,26 @@ +export const translationMethods = [ + { value: "google", label: "Google Translate" }, + { value: "deepl", label: "DeepL" }, + { value: "deeplx", label: "DeepLX(免费,无需填 API)" }, +]; + +export type LanguageOption = { + value: string; + label: string; +}; + +export const languages: LanguageOption[] = [ + { value: "en", label: "英语(English)" }, + { value: "zh", label: "中文(Chinese)" }, + { value: "ja", label: "日本語" }, + { value: "ko", label: "韩语(한국어)" }, + { value: "es", label: "西班牙语" }, + { value: "fr", label: "法语(Français)" }, + { value: "de", label: "德语(Deutsch)" }, + { value: "it", label: "意大利语" }, + { value: "ru", label: "俄语(Русский)" }, + { value: "pt", label: "葡萄牙语" }, + { value: "ar", label: "阿拉伯语" }, + { value: "hi", label: "印地语 (仅 Google)" }, + { value: "bn", label: "孟加拉语 (仅 Google)" }, +]; diff --git a/src/app/json-translate/client.tsx b/src/app/json-translate/client.tsx index 254df93..cd0c36d 100644 --- a/src/app/json-translate/client.tsx +++ b/src/app/json-translate/client.tsx @@ -6,6 +6,7 @@ import { JSONPath } from "jsonpath-plus"; import { translateText } from "../components/translateText"; import { preprocessJson } from "../components/preprocessJson"; import KeyMappingInput from "../components/KeyMappingInput"; +import { translationMethods, languages } from "../components/transalteConstants"; const { Title, Paragraph } = Typography; @@ -26,33 +27,6 @@ const JsonTranslate = () => { setShowSimpleInput(!showSimpleInput); }; - const translationMethods = [ - { value: "google", label: "Google Translate" }, - { value: "deepl", label: "DeepL" }, - { value: "deeplx", label: "DeepLX(免费,无需填 API)" }, - ]; - - type LanguageOption = { - value: string; - label: string; - }; - - const languages: LanguageOption[] = [ - { value: "en", label: "英语(English)" }, - { value: "zh", label: "中文(Chinese)" }, - { value: "ja", label: "日本語" }, - { value: "ko", label: "韩语(한국어)" }, - { value: "es", label: "西班牙语" }, - { value: "fr", label: "法语(Français)" }, - { value: "de", label: "德语(Deutsch)" }, - { value: "it", label: "意大利语" }, - { value: "ru", label: "俄语(Русский)" }, - { value: "pt", label: "葡萄牙语" }, - { value: "hi", label: "印地语 (仅 Google)" }, - { value: "ar", label: "阿拉伯语 (仅 Google)" }, - { value: "bn", label: "孟加拉语 (仅 Google)" }, - ]; - const handleJsonInputChange = (e) => { const input = e.target.value; setJsonInput(input);