hex/ios/HEXShared/FullKeyboard/LanguageLearning.swift
Dax a0a7da5ef8
ios: learn each language separately (experiment) (#2188)
* ios: learn each language separately (experiment)

* ios: split KeyboardSurface under the file cap

* ios: per-language learning review fixes
2026-11-21 09:00:58 -05:00

23 lines
1.2 KiB
Swift

import Foundation
/// Experiment (Learn each language separately): what the keys and dictation learn stays with
/// the language it was typed or dictated in. Corrections and dictation fixes are tagged with
/// their language either way, so turning it on needs nothing learned again; off, one shared
/// list and one shared learning, exactly as before.
nonisolated enum LanguageLearning {
/// The code a dictation's fixes are kept under: its base language, so English heard in
/// the US and in the UK stays one list ("en" for "en-US" and "en-GB").
static func dictationCode(_ identifier: String?) -> String? {
guard let identifier else { return nil }
return Locale(identifier: identifier).language.languageCode?.identifier ?? identifier
}
}
extension TypingLearning {
/// `derive(from:)` over the corrections typed in `language` and the ones never tagged;
/// nil derives from all of them, as before.
static func derive(from corrections: [TypingJournalCorrection], language: String?) -> TypingLearning {
guard let language else { return derive(from: corrections) }
return derive(from: corrections.filter { $0.language == nil || $0.language == language })
}
}