增加 i18n 示例
Some checks failed
Build / build (push) Has been cancelled

This commit is contained in:
ivamp 2024-10-15 01:01:14 +08:00
parent 3f60f29806
commit bbfb41f706
8 changed files with 73 additions and 17 deletions

View File

@ -11,7 +11,6 @@
"gen": "openapi-generator-cli generate -i ./api/swagger.yaml -g typescript-axios -o ./src/api" "gen": "openapi-generator-cli generate -i ./api/swagger.yaml -g typescript-axios -o ./src/api"
}, },
"dependencies": { "dependencies": {
"@kangc/v-md-editor": "^2.3.18",
"@notable/html2markdown": "^2.0.3", "@notable/html2markdown": "^2.0.3",
"@traptitech/markdown-it-katex": "^3.6.0", "@traptitech/markdown-it-katex": "^3.6.0",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
@ -20,9 +19,11 @@
"js-base64": "^3.7.7", "js-base64": "^3.7.7",
"katex": "^0.16.11", "katex": "^0.16.11",
"lottie-web": "^5.12.2", "lottie-web": "^5.12.2",
"markdown-it": "^14.1.0",
"pinia": "^2.2.2", "pinia": "^2.2.2",
"pinia-plugin-persistedstate": "^4.0.0", "pinia-plugin-persistedstate": "^4.0.0",
"vooks": "^0.2.12" "vooks": "^0.2.12",
"vue-i18n": "10"
}, },
"devDependencies": { "devDependencies": {
"@babel/types": "^7.18.10", "@babel/types": "^7.18.10",

9
src/i18n/en.json Normal file
View File

@ -0,0 +1,9 @@
{
"guest": {
"subtitle": "下一代智能体平台,为您的数字生活带来革命性变化",
"try-now": "立即尝试",
"tokens_current_month": "本月处理 Tokens",
"tool_calls_current_month": "本月工具调用",
"wordpress_plugin": "WordPress 插件"
}
}

9
src/i18n/index.ts Normal file
View File

@ -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,
};

9
src/i18n/zh-CN.json Normal file
View File

@ -0,0 +1,9 @@
{
"guest": {
"subtitle": "下一代智能体平台,为您的数字生活带来革命性变化",
"try-now": "立即尝试",
"tokens_current_month": "本月处理 Tokens",
"tool_calls_current_month": "本月工具调用",
"wordpress_plugin": "WordPress 插件"
}
}

9
src/i18n/zh-TW.json Normal file
View File

@ -0,0 +1,9 @@
{
"guest": {
"subtitle": "下一代智能体平台,为您的数字生活带来革命性变化",
"try-now": "立即尝试",
"tokens_current_month": "本月处理 Tokens",
"tool_calls_current_month": "本月工具调用",
"wordpress_plugin": "WordPress 插件"
}
}

View File

@ -6,22 +6,19 @@ import "./styles/style.css";
import "./styles/color.less"; import "./styles/color.less";
import "animate.css"; import "animate.css";
import { createApp } from 'vue' import { createApp } from "vue";
import App from './App.vue' import App from "./App.vue";
import naive from 'naive-ui'
import router from "./router"; import router from "./router";
import { registerPlugins } from "./plugins"; import { registerPlugins } from "./plugins";
const app = createApp(App) const app = createApp(App);
app.use(naive)
registerPlugins(app); registerPlugins(app);
app.use(router); app.use(router);
if (process.env.NODE_ENV === "production") { if (process.env.NODE_ENV === "production") {
setTimeout(() => { setTimeout(() => {
const appContainer = document.getElementById("app"); const appContainer = document.getElementById("app");

View File

@ -9,10 +9,10 @@
Leaflow <span class="amber-text">Amber</span> Leaflow <span class="amber-text">Amber</span>
</h1> </h1>
<p class="subtitle"> <p class="subtitle">
下一代智能体平台为您的数字生活带来革命性变化 <span>{{ $t('guest.subtitle') }}</span>
<br class="mobile-break" /> <br class="mobile-break" />
<a @click="gotoLogin" class="cta-link cursor-pointer" <a @click="gotoLogin" class="cta-link cursor-pointer"
>立即体验 🚀</a >{{ $t('guest.try-now') }}</a
> >
</p> </p>
<div <div
@ -32,7 +32,7 @@
/> />
<template #suffix> Tokens </template> <template #suffix> Tokens </template>
</n-statistic> </n-statistic>
<div class="stat-label">本月处理 Tokens</div> <div class="stat-label">{{ $t('guest.tokens_current_month') }}</div>
</div> </div>
<div class="stat-item"> <div class="stat-item">
<n-statistic tabular-nums> <n-statistic tabular-nums>
@ -47,7 +47,7 @@
/> />
<template #suffix> Calls </template> <template #suffix> Calls </template>
</n-statistic> </n-statistic>
<div class="stat-label">本月工具调用</div> <div class="stat-label">{{ $t('guest.tool_calls_current_month') }}</div>
</div> </div>
</div> </div>
<div class="button-group"> <div class="button-group">
@ -58,8 +58,7 @@
href="https://github.com/ivampiresp/wp-amber" href="https://github.com/ivampiresp/wp-amber"
target="_blank" target="_blank"
> >
WordPress 插件 {{ $t('guest.wordpress_plugin') }} </n-button>
</n-button>
<n-button <n-button
class="transparent-button spotlight-button" class="transparent-button spotlight-button"
ghost ghost

View File

@ -1,6 +1,7 @@
import pinia from "../stores"; import pinia from "../stores";
import naive from "naive-ui"; import naive from "naive-ui";
import { createI18n } from "vue-i18n";
import i18nMessages from "@/i18n"
// Types // Types
import type { App } from "vue"; import type { App } from "vue";
// 通用字体 // 通用字体
@ -8,6 +9,28 @@ import "vfonts/Lato.css";
// 等宽字体 // 等宽字体
import "vfonts/FiraCode.css"; import "vfonts/FiraCode.css";
export function registerPlugins(app: App) { // 自动根据用户的浏览器设置选择语言
app.use(naive).use(pinia); const getLocate = () => {
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(i18n).use(naive).use(pinia);
} }