fix(panel): keep the picked language when overriding the target
The header language picker set the effective target and then re-ran prepare, where TranslationDirectionPolicy only knew a Bool override and returned the mother tongue. Any picked language other than the mother tongue was discarded, so the panel appeared not to change. The policy now takes the override target itself, and PanelViewModel stores it, so a picker choice wins over a rule for that capture; a new capture returns to the rule/mother tongue. Move the shared panel test scaffolding into PanelTestSupport and the routing tests into PanelRoutingTests, and add picker and rule-override tests. Verified: make verify green; live checks with a German -> English rule show the picker switching to French, the next capture back to English with the banner, and the banner override to German.
This commit is contained in:
1 parent
bd8e3db82d
commit
9f89000b0d
8 files changed
+382
-316
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import SprachmittlerText
|
||||
|
||||
/// The effective target for one translation, after an optional reverse-direction switch.
|
||||
/// The effective target for one translation, after a language rule or an explicit override.
|
||||
public struct TranslationDirection: Sendable, Equatable {
|
||||
/// The language the request will translate into.
|
||||
public let target: ModelLanguage
|
||||
@@ -26,14 +26,17 @@ public enum TranslationDirectionPolicy {
|
||||
/// - configuredTarget: The user's mother tongue, used when no rule matches.
|
||||
/// - routes: The source-to-target rules.
|
||||
/// - detection: The advisory source-language detection.
|
||||
/// - override: True after an explicit target choice for the current capture.
|
||||
/// - override: An explicit target choice for the current capture, or nil to use the routes.
|
||||
public static func resolve(
|
||||
configuredTarget: ModelLanguage,
|
||||
routes: [LanguageRoute],
|
||||
detection: LanguageDetection?,
|
||||
override: Bool
|
||||
override: ModelLanguage?
|
||||
) -> TranslationDirection {
|
||||
guard !override, let detection else {
|
||||
if let override {
|
||||
return TranslationDirection(target: override, didRoute: false, source: nil)
|
||||
}
|
||||
guard let detection else {
|
||||
return TranslationDirection(target: configuredTarget, didRoute: false, source: nil)
|
||||
}
|
||||
for route in routes {
|
||||
|
||||
Reference in new issue
Block a user