Skip to content

Commit 5487201

Browse files
authored
feat: 新增「通用设置 > 外观设置 > 语言」配置项 (#645)
1 parent 0eac8e4 commit 5487201

29 files changed

Lines changed: 447 additions & 96 deletions

File tree

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,9 @@
5151
],
5252

5353
"typescript.enablePromptUseWorkspaceTsdk": true,
54-
"typescript.tsdk": "./node_modules/typescript/lib"
54+
"typescript.tsdk": "./node_modules/typescript/lib",
55+
56+
"i18n-ally.localesPaths": ["src/locales"],
57+
"i18n-ally.keystyle": "nested",
58+
"i18n-ally.displayLanguage": "zh-CN"
5559
}

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
"pinia": "^3.0.3",
4444
"pixi-live2d-display": "^0.4.0",
4545
"pixi.js": "^6.5.10",
46+
"tauri-plugin-locale-api": "^2.0.1",
4647
"tauri-plugin-macos-permissions-api": "^2.3.0",
4748
"vue": "^3.5.16",
49+
"vue-i18n": "^11.1.12",
4850
"vue-markdown-render": "^2.2.1",
4951
"vue-router": "^4.5.1",
5052
"vue3-masonry-css": "^1.0.7"

pnpm-lock.yaml

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ tauri-plugin-fs = "2"
3737
fs_extra = "1"
3838
tauri-plugin-clipboard-manager = "2"
3939
tauri-plugin-global-shortcut = "2"
40+
tauri-plugin-locale = "2"
4041
rdev = { git = "https://github.com/kunkunsh/rdev" }
4142
gilrs = { git = "https://github.com/ayangweb/gilrs", default-features = false, features = ["xinput"] }
4243

src-tauri/capabilities/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"clipboard-manager:allow-write-text",
4747
"global-shortcut:allow-is-registered",
4848
"global-shortcut:allow-register",
49-
"global-shortcut:allow-unregister"
49+
"global-shortcut:allow-unregister",
50+
"locale:default"
5051
]
5152
}

src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub fn run() {
6060
.plugin(tauri_plugin_fs::init())
6161
.plugin(tauri_plugin_clipboard_manager::init())
6262
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
63+
.plugin(tauri_plugin_locale::init())
6364
.on_window_event(|window, event| match event {
6465
WindowEvent::CloseRequested { api, .. } => {
6566
let _ = window.hide();

src/App.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import { error } from '@tauri-apps/plugin-log'
44
import { openUrl } from '@tauri-apps/plugin-opener'
55
import { useEventListener } from '@vueuse/core'
66
import { ConfigProvider, theme } from 'ant-design-vue'
7-
import zhCN from 'ant-design-vue/es/locale/zh_CN'
87
import { isString } from 'es-toolkit'
98
import isURL from 'is-url'
10-
import { onMounted } from 'vue'
9+
import { onMounted, watch } from 'vue'
10+
import { useI18n } from 'vue-i18n'
1111
import { RouterView } from 'vue-router'
1212
1313
import { useTauriListen } from './composables/useTauriListen'
1414
import { useThemeVars } from './composables/useThemeVars'
1515
import { useWindowState } from './composables/useWindowState'
16-
import { LISTEN_KEY } from './constants'
16+
import { LANGUAGE, LISTEN_KEY } from './constants'
17+
import { getAntdLocale } from './locales/index.ts'
1718
import { hideWindow, showWindow } from './plugins/window'
1819
import { useAppStore } from './stores/app'
1920
import { useCatStore } from './stores/cat'
@@ -30,6 +31,7 @@ const shortcutStore = useShortcutStore()
3031
const appWindow = getCurrentWebviewWindow()
3132
const { isRestored, restoreState } = useWindowState()
3233
const { darkAlgorithm, defaultAlgorithm } = theme
34+
const { locale } = useI18n()
3335
3436
onMounted(async () => {
3537
generateColorVars()
@@ -39,10 +41,15 @@ onMounted(async () => {
3941
await modelStore.$tauri.start()
4042
await modelStore.init()
4143
await catStore.$tauri.start()
44+
catStore.init()
4245
await generalStore.$tauri.start()
46+
await generalStore.init()
4347
await shortcutStore.$tauri.start()
4448
await restoreState()
45-
catStore.init()
49+
})
50+
51+
watch(() => generalStore.appearance.language, (value) => {
52+
locale.value = value ?? LANGUAGE.EN_US
4653
})
4754
4855
useTauriListen(LISTEN_KEY.SHOW_WINDOW, ({ payload }) => {
@@ -82,7 +89,7 @@ useEventListener('click', (event) => {
8289

8390
<template>
8491
<ConfigProvider
85-
:locale="zhCN"
92+
:locale="getAntdLocale(generalStore.appearance.language)"
8693
:theme="{
8794
algorithm: generalStore.appearance.isDark ? darkAlgorithm : defaultAlgorithm,
8895
}"

src/components/pro-shortcut/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function handleKeyUp(event: KeyboardEvent) {
110110
@mouseover="isHovering = true"
111111
>
112112
<span v-if="pressedKeys.length === 0">
113-
{{ isFocusing ? '按下录制快捷键' : '点击录制快捷键' }}
113+
{{ isFocusing ? $t('components.proShortcut.hints.pressRecordShortcut') : $t('components.proShortcut.hints.clickRecordShortcut') }}
114114
</span>
115115

116116
<span class="text-primary font-bold">

src/composables/useSharedMenu.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { CheckMenuItem, MenuItem, PredefinedMenuItem, Submenu } from '@tauri-apps/api/menu'
22
import { range } from 'es-toolkit'
3+
import { useI18n } from 'vue-i18n'
34

45
import { showWindow } from '@/plugins/window'
56
import { useCatStore } from '@/stores/cat'
67
import { isMac } from '@/utils/platform'
78

89
export function useSharedMenu() {
910
const catStore = useCatStore()
11+
const { t } = useI18n()
1012

1113
const getScaleMenuItems = async () => {
1214
const options = range(50, 151, 25)
1315

1416
const items = options.map((item) => {
1517
return CheckMenuItem.new({
16-
text: item === 100 ? '默认' : `${item}%`,
18+
text: `${item}%`,
1719
checked: catStore.window.scale === item,
1820
action: () => {
1921
catStore.window.scale = item
@@ -59,30 +61,30 @@ export function useSharedMenu() {
5961
const getSharedMenu = async () => {
6062
return await Promise.all([
6163
MenuItem.new({
62-
text: '偏好设置...',
64+
text: t('composables.useSharedMenu.labels.preference'),
6365
accelerator: isMac ? 'Cmd+,' : '',
6466
action: () => showWindow('preference'),
6567
}),
6668
MenuItem.new({
67-
text: catStore.window.visible ? '隐藏猫咪' : '显示猫咪',
69+
text: catStore.window.visible ? t('composables.useSharedMenu.labels.hideCat') : t('composables.useSharedMenu.labels.showCat'),
6870
action: () => {
6971
catStore.window.visible = !catStore.window.visible
7072
},
7173
}),
7274
PredefinedMenuItem.new({ item: 'Separator' }),
7375
CheckMenuItem.new({
74-
text: '窗口穿透',
76+
text: t('composables.useSharedMenu.labels.passThrough'),
7577
checked: catStore.window.passThrough,
7678
action: () => {
7779
catStore.window.passThrough = !catStore.window.passThrough
7880
},
7981
}),
8082
Submenu.new({
81-
text: '窗口尺寸',
83+
text: t('composables.useSharedMenu.labels.windowSize'),
8284
items: await getScaleMenuItems(),
8385
}),
8486
Submenu.new({
85-
text: '不透明度',
87+
text: t('composables.useSharedMenu.labels.opacity'),
8688
items: await getOpacityMenuItems(),
8789
}),
8890
])

0 commit comments

Comments
 (0)