Skip to content

Commit 7e53322

Browse files
committed
feat(国际化): 在GUI设置中添加语言字段,并实现前后端语言设置和获取接口
初始化时从后端获取当前语言设置,切换语言时同步到后端存储
1 parent d11599b commit 7e53322

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

app.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,36 @@ func (a *App) GetDisableRightClick() bool {
784784
return settings.DisableRightClick
785785
}
786786

787+
// SetLanguage sets the GUI language
788+
func (a *App) SetLanguage(lang string) error {
789+
a.mu.Lock()
790+
defer a.mu.Unlock()
791+
792+
// Save to GUI settings
793+
settings, err := redc.LoadGUISettings()
794+
if err != nil {
795+
return err
796+
}
797+
settings.Language = lang
798+
return redc.SaveGUISettings(settings)
799+
}
800+
801+
// GetLanguage returns the current GUI language
802+
func (a *App) GetLanguage() string {
803+
a.mu.Lock()
804+
defer a.mu.Unlock()
805+
806+
// Load from GUI settings
807+
settings, err := redc.LoadGUISettings()
808+
if err != nil {
809+
return "zh"
810+
}
811+
if settings.Language == "" {
812+
return "zh"
813+
}
814+
return settings.Language
815+
}
816+
787817
// maskValue returns masked value for display (shows last 4 chars if length > 8)
788818
func maskValue(value string) string {
789819
if value == "" {

frontend/src/App.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { onMount, onDestroy } from 'svelte';
44
import { i18n as i18nData } from './lib/i18n.js';
55
import { EventsOn, EventsOff, WindowMinimise, WindowMaximise, WindowUnmaximise, WindowIsMaximised, Quit, Environment } from '../wailsjs/runtime/runtime.js';
6-
import { ListCases, ListTemplates, GetConfig, GetVersion, GetMCPStatus, StartMCPServer, StopMCPServer, GetResourceSummary, GetBalances, GetTerraformMirrorConfig, GetNotificationEnabled, GetCurrentProject, ListProjects, SwitchProject, CreateProject, GetDisableRightClick, SetDisableRightClick, CheckForUpdates } from '../wailsjs/go/main/App.js';
6+
import { ListCases, ListTemplates, GetConfig, GetVersion, GetMCPStatus, StartMCPServer, StopMCPServer, GetResourceSummary, GetBalances, GetTerraformMirrorConfig, GetNotificationEnabled, GetCurrentProject, ListProjects, SwitchProject, CreateProject, GetDisableRightClick, SetDisableRightClick, CheckForUpdates, GetLanguage, SetLanguage } from '../wailsjs/wailsjs/go/main/App.js';
77
import Console from './components/Console/Console.svelte';
88
import CloudResources from './components/Resources/CloudResources.svelte';
99
import Compose from './components/Compose/Compose.svelte';
@@ -52,7 +52,7 @@
5252
let projectLoading = $state(false);
5353
5454
// i18n state
55-
let lang = $state(localStorage.getItem('lang') || 'zh');
55+
let lang = $state('zh');
5656
const i18n = { ...i18nData };
5757
let t = $derived(i18n[lang]);
5858
@@ -64,6 +64,7 @@
6464
function toggleLang() {
6565
lang = lang === 'zh' ? 'en' : 'zh';
6666
localStorage.setItem('lang', lang);
67+
SetLanguage(lang).catch(console.error);
6768
}
6869
6970
// Project management functions
@@ -180,13 +181,14 @@
180181
isLoading = true;
181182
error = '';
182183
try {
183-
[cases, templates, config, terraformMirror, notificationEnabled, rightClickDisabled, appVersion] = await Promise.all([
184+
[cases, templates, config, terraformMirror, notificationEnabled, rightClickDisabled, lang, appVersion] = await Promise.all([
184185
ListCases(),
185186
ListTemplates(),
186187
GetConfig(),
187188
GetTerraformMirrorConfig(),
188189
GetNotificationEnabled(),
189190
GetDisableRightClick(),
191+
GetLanguage(),
190192
GetVersion()
191193
]);
192194
rightClickDisabledSync = rightClickDisabled;

frontend/wailsjs/wailsjs/go/main/App.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export function GetDisableRightClick():Promise<boolean>;
9494

9595
export function GetInstanceTypes(arg1:string,arg2:string):Promise<Array<mod.InstanceType>>;
9696

97+
export function GetLanguage():Promise<string>;
98+
9799
export function GetMCPStatus():Promise<main.MCPStatus>;
98100

99101
export function GetNotificationEnabled():Promise<boolean>;
@@ -190,6 +192,8 @@ export function SetDebugLogging(arg1:boolean):Promise<void>;
190192

191193
export function SetDisableRightClick(arg1:boolean):Promise<void>;
192194

195+
export function SetLanguage(arg1:string):Promise<void>;
196+
193197
export function SetNotificationEnabled(arg1:boolean):Promise<void>;
194198

195199
export function StartCase(arg1:string):Promise<void>;

frontend/wailsjs/wailsjs/go/main/App.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ export function GetInstanceTypes(arg1, arg2) {
178178
return window['go']['main']['App']['GetInstanceTypes'](arg1, arg2);
179179
}
180180

181+
export function GetLanguage() {
182+
return window['go']['main']['App']['GetLanguage']();
183+
}
184+
181185
export function GetMCPStatus() {
182186
return window['go']['main']['App']['GetMCPStatus']();
183187
}
@@ -370,6 +374,10 @@ export function SetDisableRightClick(arg1) {
370374
return window['go']['main']['App']['SetDisableRightClick'](arg1);
371375
}
372376

377+
export function SetLanguage(arg1) {
378+
return window['go']['main']['App']['SetLanguage'](arg1);
379+
}
380+
373381
export function SetNotificationEnabled(arg1) {
374382
return window['go']['main']['App']['SetNotificationEnabled'](arg1);
375383
}

mod/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type GUISettings struct {
3434
HttpsProxy string `json:"httpsProxy"`
3535
Socks5Proxy string `json:"socks5Proxy"`
3636
NoProxy string `json:"noProxy"`
37+
Language string `json:"language"`
3738
}
3839

3940
// Config 配置文件结构体,新增厂商配置也需要再这里添加

0 commit comments

Comments
 (0)