feat(translation-v2): refactor translationEnabled into computed + onboarding row visibility

This commit is contained in:
2026-06-25 13:52:13 +08:00
parent 4d92999347
commit 9b759281cc
11 changed files with 226 additions and 180 deletions
+15 -17
View File
@@ -35,11 +35,10 @@ public struct AppGroupPersistor {
state.mode = .polish
state.engineMode = store.engineMode
state.localASRBackend = store.localASRBackend
// v0.2.1: translation toggle + target locale. Read once at
// hydration; `refreshRuntimeFlags` keeps them in sync while the
// keyboard stays open so a Settings change shows up without a
// re-present cycle.
state.translationEnabled = store.translationEnabled
// v0.2.1 follow-up: only the target locale is persisted
// `translationEnabled` is derived from it. Hydrate once at
// startup; `refreshRuntimeFlags` keeps the chip in sync while
// the keyboard stays open.
state.translationTargetLocaleId = store.translationTargetLocaleId
// v0.2.0: iOS `SpeechAnalyzer` is always ready; mirror that
// into the State flags so downstream consumers see the same
@@ -81,10 +80,8 @@ public struct AppGroupPersistor {
let store = AppGroupStore()
state.engineMode = store.engineMode
state.localASRBackend = store.localASRBackend
// v0.2.1: keep translation state in sync with the host app so the
// chip on the keyboard reflects the latest value without a re-
// present cycle.
state.translationEnabled = store.translationEnabled
// v0.2.1 follow-up: same as `load` only the locale is
// persisted, `enabled` is derived.
state.translationTargetLocaleId = store.translationTargetLocaleId
// v0.2.0: iOS `SpeechAnalyzer` is always ready. Keep these
// toggles here so the keyboard UI doesn't flicker if the host
@@ -117,14 +114,15 @@ public struct AppGroupPersistor {
AppGroupStore().setLocalASRBackend(localASRBackend)
}
/// v0.2.1: persist translation toggle. Wired through the
/// `KeyboardViewController.setTranslation` action hook.
public func persist(translationEnabled: Bool) {
guard AppGroup.isAvailable else { return }
AppGroupStore().setTranslationEnabled(translationEnabled)
}
/// v0.2.1: persist translation target locale id (e.g. `"en"`).
/// v0.2.1: persist translation target locale id (e.g. `"en"`,
/// `"ja"`, or `TranslationLanguageCatalog.offLocaleId`). The
/// chip / picker call this through `KeyboardState.setTranslationTargetLocaleId`.
///
/// v0.2.1 follow-up: removed `persist(translationEnabled:)` the
/// enabled state is derived from the locale id, so callers only
/// need to write the locale. Keeping the legacy Bool overload
/// around would have implied that there's a separate on/off
/// switch to persist, which is no longer the model.
public func persist(translationTargetLocaleId: String) {
guard AppGroup.isAvailable else { return }
AppGroupStore().setTranslationTargetLocaleId(translationTargetLocaleId)