mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* iOS: Italian, French and Portuguese full-keyboard layouts that autocorrect in their own language A TestFlight tester on build 31 with an Italian iPhone reported that Hex kept autocorrecting their Italian into English. KeyboardLanguage only knew en, nb, es and de, so Automatic mapped an it-IT dictation language (and any other language without a layout) to English: English letters, and UITextChecker's en_US dictionary rewriting Italian words. Adds italian/french/portuguese cases. They type on the English QWERTY rows (Apple's Italian and Portuguese keyboards are QWERTY; Hex has no AZERTY yet, so French is QWERTY too), with their own long-press accent order (Italian à è ì ò ù, é right after è), their UITextChecker dictionary (it, fr, pt_BR then pt_PT), and an Italian common two-letter list. Automatic now resolves it-*, fr-* and pt-* to these; the dictation language still wins over the iPhone's keyboards, and Hebrew or Russian still get English. Automatic deliberately ignores Hex's own input mode: its primaryLanguage is the Info.plist's en-US whatever you type. Spatial autocorrect (#2059) only has en and es models; the new layouts get no model and fall back to the dictionary engine in their own language (the decoder also refuses a model of another language). The space bar already names the dictation language ("Italiano"). Snapshot scenes get Italian, French and Portuguese drafts (--dictation-language it-IT, --keyboard-layout it|fr|pt). Verified on an iOS 27.2 iPhone 17 Pro simulator: full HEXMobileTests suite (272 tests, 0 failures, 1 skipped as before). New cases in KeyboardLayoutTests, AutocorrectEngineTests and FullKeyboardEngineTests. Measured on 12 Italian sentences (19 one-slip typos, 59 correct words) with the real dictionary: English fallback fixed 4, miscorrected 4 and broke 19 correct words (Domani->Domain, stai->stay, Sono->Soon, molto->moto); Italian fixed 17, miscorrected 0 and broke none. Renders of the Italian keyboard (typing with the "ritardo" suggestion, the E and I accent menus, "Italiano" on the space bar) checked by eye. * iOS: spoken "at the rate" and "at sign" become "@", joining a spoken email address An Indian English TestFlight tester (build 32) said "at the rate", India's name for @, and got the words. Apple's on-device models don't fix it: checked on macOS 27.2 with Hex's settings and an en_IN voice, SpeechTranscriber (Hex's default) writes "My email is John at the rategmail.com." and "Send it to Priya at signyahoo.com." (gluing the domain to the word before), and DictationTranscriber writes "at the rate gmail.com", though it already writes "priya@yahoo.com" for "at sign" and "john@gmail.com" for "john at gmail dot com". SpokenCleanupRules.spokenSymbols (English only) turns "at the rate" and "at sign" into "@". Before a domain ("gmail dot com", "gmail.com", "co dot in", or glued as above), the word before (with any "dot"-joined parts) and the domain join into one lowercase address, "dot" becoming "." only there: "John at the rate Gmail dot com." becomes "john@gmail.com.". "at the rate" counts only before a domain, so "at the rate of 5%" and "at the rate we planned" stay, and "at" alone is never touched; "at sign" elsewhere is a lone "@" (but not in "at sign language"). Only the matched words change. It runs from CleanupTagger.cleanIfEnabled, which both the app's and in-keyboard dictation call: in every style but Verbatim, with Clean up what I say on or off (the experiment's guard moved below it; the tagger itself still only runs when on). TranscriptFormatter: Polished capitalized after every full stop, which would have written "john@gmail.Com."; a sentence now starts only after ".", "!" or "?" and a space, an address keeps its case (Polished and Notes), and a lone address gets no full stop. Verified on an iOS 27.2 simulator: full HEXMobileTests suite (272 tests, 0 failures, 1 skipped as before), with new cases in TranscriptCleanupTests (Apple's real outputs included) and CleanupTaggerTests.
164 lines
6.3 KiB
Swift
164 lines
6.3 KiB
Swift
import SwiftUI
|
||
import UIKit
|
||
|
||
/// Settings › Dictation language: Automatic, the first iPhone language Apple Speech
|
||
/// transcribes, or any language `SpeechTranscriber` or `DictationTranscriber` has. Shown
|
||
/// on iOS 26, where Hex dictates with Apple Speech; before it, Parakeet is English only.
|
||
struct DictationLanguageRow: View {
|
||
@Bindable var dictation: DictationController
|
||
@State private var options: [SpeechLanguageOption] = []
|
||
@State private var automaticName: String?
|
||
|
||
var body: some View {
|
||
if #available(iOS 26.0, *) {
|
||
VStack(spacing: 0) {
|
||
LanguageRowDivider()
|
||
HStack(spacing: 12) {
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
Text("Dictation language")
|
||
.font(.system(size: 15, weight: .regular))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
if dictation.dictationLanguage == nil, let automaticName {
|
||
Text(automaticName)
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.lineLimit(1)
|
||
}
|
||
}
|
||
Spacer(minLength: 8)
|
||
Menu {
|
||
Button {
|
||
dictation.setDictationLanguage(nil)
|
||
} label: {
|
||
if dictation.dictationLanguage == nil {
|
||
Label("Automatic", systemImage: "checkmark")
|
||
} else {
|
||
Text("Automatic")
|
||
}
|
||
}
|
||
Divider()
|
||
ForEach(options) { option in
|
||
Button {
|
||
dictation.setDictationLanguage(option.id)
|
||
} label: {
|
||
if dictation.dictationLanguage == option.id {
|
||
Label(option.name, systemImage: "checkmark")
|
||
} else {
|
||
Text(option.name)
|
||
}
|
||
}
|
||
}
|
||
} label: {
|
||
LanguageMenuValue(value: selectedName)
|
||
}
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.frame(minHeight: 48)
|
||
}
|
||
.task {
|
||
// The keyboard may have switched the language while Hex was away.
|
||
dictation.followDictationLanguageSetting()
|
||
options = await AppleSpeechLanguages.options()
|
||
automaticName = await AppleSpeechLanguages.automatic().map {
|
||
SpeechLanguagePicker.displayName(for: $0.identifier)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private var selectedName: String {
|
||
guard let id = dictation.dictationLanguage else { return "Automatic" }
|
||
return SpeechLanguagePicker.shortNames(for: options.map(\.id))[id]
|
||
?? SpeechLanguagePicker.displayName(for: id)
|
||
}
|
||
}
|
||
|
||
/// Settings › Keyboard › Keyboard layout (while the full keyboard is on): Automatic (the dictation language's
|
||
/// layout), English, Norsk, Español, Deutsch, Italiano, Français, or Português.
|
||
struct KeyboardLayoutRow: View {
|
||
@State private var setting = LanguageSettings().keyboardLayout
|
||
|
||
private var automatic: KeyboardLanguage {
|
||
KeyboardLanguage.automatic(
|
||
dictationLanguage: LanguageSettings().effectiveDictationLanguage,
|
||
inputModes: UITextInputMode.activeInputModes.compactMap(\.primaryLanguage),
|
||
preferredLanguages: Locale.preferredLanguages
|
||
)
|
||
}
|
||
|
||
var body: some View {
|
||
VStack(spacing: 0) {
|
||
Divider()
|
||
.overlay(HexTheme.borderWeak)
|
||
.padding(.leading, 16)
|
||
|
||
HStack(spacing: 12) {
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
Text("Keyboard layout")
|
||
.font(.system(size: 15, weight: .regular))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
if setting == nil {
|
||
Text("\(automatic.displayName), like your dictation language")
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
}
|
||
}
|
||
Spacer(minLength: 8)
|
||
Menu {
|
||
choice(nil, title: "Automatic")
|
||
Divider()
|
||
ForEach(KeyboardLanguage.allCases, id: \.self) { language in
|
||
choice(language, title: language.displayName)
|
||
}
|
||
} label: {
|
||
LanguageMenuValue(value: setting?.displayName ?? "Automatic")
|
||
}
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 10)
|
||
}
|
||
.onAppear { setting = LanguageSettings().keyboardLayout }
|
||
}
|
||
|
||
private func choice(_ language: KeyboardLanguage?, title: String) -> some View {
|
||
Button {
|
||
setting = language
|
||
LanguageSettings().keyboardLayout = language
|
||
} label: {
|
||
if setting == language {
|
||
Label(title, systemImage: "checkmark")
|
||
} else {
|
||
Text(title)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// The settings card's row divider.
|
||
private struct LanguageRowDivider: View {
|
||
var body: some View {
|
||
Rectangle()
|
||
.fill(HexTheme.borderWeak)
|
||
.frame(height: 0.5)
|
||
.padding(.leading, 16)
|
||
}
|
||
}
|
||
|
||
/// A menu's current value with the up-down chevron, as the settings card's other menus show it.
|
||
private struct LanguageMenuValue: View {
|
||
let value: String
|
||
|
||
var body: some View {
|
||
HStack(spacing: 5) {
|
||
Text(value)
|
||
.font(.system(size: 15, weight: .regular))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.lineLimit(1)
|
||
Image(systemName: "chevron.up.chevron.down")
|
||
.font(.system(size: 11, weight: .medium))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
}
|
||
.padding(.vertical, 6)
|
||
.contentShape(Rectangle())
|
||
}
|
||
}
|