fix(l10n): 观察宿主语言变化并即时刷新界面

This commit is contained in:
2026-11-03 20:43:04 +08:00
parent 3b1e711556
commit 7109d483b6
6 changed files with 77 additions and 9 deletions
+10 -9
View File
@@ -25,9 +25,9 @@ import AppKit
func applicationWillFinishLaunching(_ notification: Notification) {
let settings = NSHostingSceneRepresentation {
Settings {
AppearanceSettingsView(preferences: appearance, language: language, sampling: metrics.sampling, presentation: presentation)
.environment(\.locale, language.locale)
.onChange(of: language.language) { _, _ in self.configureMainMenu() }
AppLanguageScope(preferences: language, onChange: { self.configureMainMenu() }) { [self] in
AppearanceSettingsView(preferences: appearance, language: language, sampling: metrics.sampling, presentation: presentation)
}
}
}
NSApp.addSceneRepresentation(settings)
@@ -38,12 +38,13 @@ import AppKit
menuTitle: { [language] key in
AppLocalization.string("status." + key, locale: language.locale, table: "StatusItem")
}, openSettings: { [weak self] in self?.settingsCommand() }) { [self] panel in
MenuPanelView(metrics: metrics, preferences: appearance, keepAwake: awake, settingsPresentation: presentation,
presentation: panel, onOpenSettings: { [weak self] in
self?.menuBar?.hide()
settings.environment.openSettings()
})
.environment(\.locale, language.locale)
AppLanguageScope(preferences: language) {
MenuPanelView(metrics: metrics, preferences: appearance, keepAwake: awake, settingsPresentation: presentation,
presentation: panel, onOpenSettings: { [weak self] in
self?.menuBar?.hide()
settings.environment.openSettings()
})
}
}
}