7f059dbd45
Migrate keyboard dictation to continuous Flow sessions with auto-start, tap-to-toggle recording, 60s countdown, five-step onboarding, and App Group IPC. Add docs/ GitHub Pages site with en/zh privacy policy for App Store compliance.
26 lines
1.0 KiB
Swift
26 lines
1.0 KiB
Swift
// SpeechLocaleResolver.swift
|
|
// OSGKeyboard · Shared
|
|
//
|
|
// Maps persisted `localeId` settings to a `Locale` suitable for
|
|
// `DictationTranscriber.supportedLocale(equivalentTo:)`.
|
|
|
|
import Foundation
|
|
|
|
public enum SpeechLocaleResolver {
|
|
/// Resolve a stored locale id (`auto`, `zh-Hans`, …) for on-device ASR.
|
|
public static func resolve(_ localeId: String) -> Locale {
|
|
let raw: String
|
|
if localeId == "auto" {
|
|
raw = Locale.preferredLanguages.first ?? "en-US"
|
|
} else {
|
|
raw = localeId
|
|
}
|
|
let normalized = raw.replacingOccurrences(of: "_", with: "-").lowercased()
|
|
if normalized.hasPrefix("zh") { return Locale(identifier: "zh-Hans") }
|
|
if normalized.hasPrefix("ja") { return Locale(identifier: "ja-JP") }
|
|
if normalized.hasPrefix("ko") { return Locale(identifier: "ko-KR") }
|
|
if normalized.hasPrefix("en") { return Locale(identifier: "en-US") }
|
|
return Locale(identifier: raw.replacingOccurrences(of: "_", with: "-"))
|
|
}
|
|
}
|