From bbfb41f706477baca54c077ae3b418740a5764d7 Mon Sep 17 00:00:00 2001 From: ivamp Date: Tue, 15 Oct 2024 01:01:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20i18n=20=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 +++-- src/i18n/en.json | 9 +++++++++ src/i18n/index.ts | 9 +++++++++ src/i18n/zh-CN.json | 9 +++++++++ src/i18n/zh-TW.json | 9 +++++++++ src/main.ts | 11 ++++------- src/pages/Guest.vue | 11 +++++------ src/plugins/index.ts | 27 +++++++++++++++++++++++++-- 8 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 src/i18n/en.json create mode 100644 src/i18n/index.ts create mode 100644 src/i18n/zh-CN.json create mode 100644 src/i18n/zh-TW.json diff --git a/package.json b/package.json index 42db299..27554d8 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "gen": "openapi-generator-cli generate -i ./api/swagger.yaml -g typescript-axios -o ./src/api" }, "dependencies": { - "@kangc/v-md-editor": "^2.3.18", "@notable/html2markdown": "^2.0.3", "@traptitech/markdown-it-katex": "^3.6.0", "animate.css": "^4.1.1", @@ -20,9 +19,11 @@ "js-base64": "^3.7.7", "katex": "^0.16.11", "lottie-web": "^5.12.2", + "markdown-it": "^14.1.0", "pinia": "^2.2.2", "pinia-plugin-persistedstate": "^4.0.0", - "vooks": "^0.2.12" + "vooks": "^0.2.12", + "vue-i18n": "10" }, "devDependencies": { "@babel/types": "^7.18.10", diff --git a/src/i18n/en.json b/src/i18n/en.json new file mode 100644 index 0000000..6d270ae --- /dev/null +++ b/src/i18n/en.json @@ -0,0 +1,9 @@ +{ + "guest": { + "subtitle": "下一代智能体平台,为您的数字生活带来革命性变化", + "try-now": "立即尝试", + "tokens_current_month": "本月处理 Tokens", + "tool_calls_current_month": "本月工具调用", + "wordpress_plugin": "WordPress 插件" + } +} diff --git a/src/i18n/index.ts b/src/i18n/index.ts new file mode 100644 index 0000000..583eae9 --- /dev/null +++ b/src/i18n/index.ts @@ -0,0 +1,9 @@ +import zhCN from "./zh-CN.json"; +import zhTW from "./zh-TW.json"; +import en from "./en.json"; + +export default { + "zh-CN": zhCN, + "zh-TW": zhTW, + en: en, +}; diff --git a/src/i18n/zh-CN.json b/src/i18n/zh-CN.json new file mode 100644 index 0000000..6d270ae --- /dev/null +++ b/src/i18n/zh-CN.json @@ -0,0 +1,9 @@ +{ + "guest": { + "subtitle": "下一代智能体平台,为您的数字生活带来革命性变化", + "try-now": "立即尝试", + "tokens_current_month": "本月处理 Tokens", + "tool_calls_current_month": "本月工具调用", + "wordpress_plugin": "WordPress 插件" + } +} diff --git a/src/i18n/zh-TW.json b/src/i18n/zh-TW.json new file mode 100644 index 0000000..6d270ae --- /dev/null +++ b/src/i18n/zh-TW.json @@ -0,0 +1,9 @@ +{ + "guest": { + "subtitle": "下一代智能体平台,为您的数字生活带来革命性变化", + "try-now": "立即尝试", + "tokens_current_month": "本月处理 Tokens", + "tool_calls_current_month": "本月工具调用", + "wordpress_plugin": "WordPress 插件" + } +} diff --git a/src/main.ts b/src/main.ts index 2f01f5c..bf753b6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,22 +6,19 @@ import "./styles/style.css"; import "./styles/color.less"; import "animate.css"; -import { createApp } from 'vue' -import App from './App.vue' - -import naive from 'naive-ui' +import { createApp } from "vue"; +import App from "./App.vue"; import router from "./router"; import { registerPlugins } from "./plugins"; -const app = createApp(App) - -app.use(naive) +const app = createApp(App); registerPlugins(app); app.use(router); + if (process.env.NODE_ENV === "production") { setTimeout(() => { const appContainer = document.getElementById("app"); diff --git a/src/pages/Guest.vue b/src/pages/Guest.vue index 7871f2d..3f15c44 100644 --- a/src/pages/Guest.vue +++ b/src/pages/Guest.vue @@ -9,10 +9,10 @@ Leaflow Amber

- 下一代智能体平台,为您的数字生活带来革命性变化 + {{ $t('guest.subtitle') }}
立即体验 🚀{{ $t('guest.try-now') }}

-
本月处理 Tokens
+
{{ $t('guest.tokens_current_month') }}
@@ -47,7 +47,7 @@ /> -
本月工具调用
+
{{ $t('guest.tool_calls_current_month') }}
@@ -58,8 +58,7 @@ href="https://github.com/ivampiresp/wp-amber" target="_blank" > - WordPress 插件 - + {{ $t('guest.wordpress_plugin') }} { + const languages = navigator.languages || [navigator.language]; + + for (const lang of languages) { + if (lang.startsWith('zh-CN')) { + return 'zh-CN'; // 简体中文 + } else if (lang.startsWith('zh-TW')) { + return 'zh-TW'; // 繁体中文 + } + } + return languages[0]; +}; + +const userLocale = getLocate(); + +const i18n = createI18n({ + locale: userLocale || 'zh-CN', // 如果没有匹配,默认返回简体中文 + fallbackLocale: "zh-CN", + messages: i18nMessages, +}); + export function registerPlugins(app: App) { - app.use(naive).use(pinia); + app.use(i18n).use(naive).use(pinia); }