feat(settings): 新增三语即时切换并记录验收与专项边界
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import Foundation
|
||||
|
||||
/// Native AppKit labels do not consume SwiftUI's locale environment.
|
||||
nonisolated enum AppLocalization {
|
||||
static func string(_ key: String, locale: Locale, bundle: Bundle = .main) -> String {
|
||||
let identifier = Bundle.preferredLocalizations(from: AppLanguage.supported,
|
||||
forPreferences: [locale.identifier]).first ?? "en"
|
||||
guard let path = bundle.path(forResource: identifier, ofType: "lproj"),
|
||||
let localized = Bundle(path: path) else {
|
||||
return bundle.localizedString(forKey: key, value: nil, table: nil)
|
||||
}
|
||||
return localized.localizedString(forKey: key, value: nil, table: nil)
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import AppKit
|
||||
|
||||
/// A non-activating child window: outside the parent layout, below no other app.
|
||||
struct HoverDetailPresenter<Detail: View>: NSViewRepresentable {
|
||||
@Environment(\.locale) private var locale
|
||||
let isPresented: Bool
|
||||
let detail: Detail
|
||||
let onHover: (Bool) -> Void
|
||||
@@ -10,7 +11,7 @@ struct HoverDetailPresenter<Detail: View>: NSViewRepresentable {
|
||||
|
||||
func makeNSView(context: Context) -> AnchorView { AnchorView() }
|
||||
func updateNSView(_ view: AnchorView, context: Context) {
|
||||
view.configure(presented: isPresented, detail: AnyView(detail), onHover: onHover, onDismiss: onDismiss)
|
||||
view.configure(presented: isPresented, detail: AnyView(detail.environment(\.locale, locale)), onHover: onHover, onDismiss: onDismiss)
|
||||
}
|
||||
static func dismantleNSView(_ view: AnchorView, coordinator: ()) { view.detach() }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user