Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit 0fff8d6

Browse files
committed
feat: get system language
1 parent ed50ef5 commit 0fff8d6

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

src-tauri/Cargo.lock

Lines changed: 13 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
@@ -19,6 +19,7 @@ serde = { version = "1.0", features = ["derive"] }
1919
serde_json = "1.0"
2020
window-shadows = "0.2.1"
2121
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
22+
current_locale = "0.1.1"
2223

2324

2425
[dependencies.tauri-plugin-sql]

src-tauri/src/commands.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ pub fn close_splashscreen(window: tauri::Window) {
5858
// 展示主视图
5959
window.get_window("main").unwrap().show().unwrap();
6060
}
61+
62+
// 获取当前系统语言
63+
#[tauri::command]
64+
pub fn get_user_language() -> String {
65+
let current_locale = current_locale::current_locale();
66+
67+
if current_locale.is_ok() {
68+
return current_locale.ok().unwrap();
69+
}
70+
71+
return "en-US".to_string();
72+
}

src-tauri/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ fn main() {
4040
}))
4141
.invoke_handler(tauri::generate_handler![
4242
commands::show_in_folder,
43-
commands::close_splashscreen
43+
commands::close_splashscreen,
44+
commands::get_user_language
4445
])
4546
.on_system_tray_event(tray::handler)
4647
.run(tauri::generate_context!())

src/App.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<script setup lang="ts">
2+
import { invoke } from '@tauri-apps/api/tauri'
23
const { isFix } = storeToRefs(useSettingsStore())
34
45
const { windowClass } = useInit()
56
67
const handleDoubleClick = () => {
78
isFix.value = !isFix.value
89
}
10+
11+
onMounted(async () => {
12+
const lang = await invoke('get_user_language')
13+
14+
// console.warn('lang', lang)
15+
})
916
</script>
1017

1118
<template>

0 commit comments

Comments
 (0)