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
+14
View File
@@ -0,0 +1,14 @@
import SwiftUI
/// Observe preferences inside a SwiftUI body, including AppKit-hosted roots.
struct AppLanguageScope<Content: View>: View {
let preferences: LanguagePreferences
var onChange: () -> Void = {}
@ViewBuilder var content: () -> Content
var body: some View {
content()
.environment(\.locale, preferences.locale)
.onChange(of: preferences.language) { _, _ in onChange() }
}
}