hex/ios/HEXShared/FullKeyboard/View/FullKeyboardView+Vocabulary.swift
Ryan Vogel f9d4c57248 iOS keyboard: Türkçe (Apple's Q, F and QWERTY – Türkçe) with Turkish's two i's
A tester on build 147 asked for a Turkish keyboard. Adds KeyboardLanguage.turkish
("tr", Türkçe), an ordinary language as Slovak's #2462 is, matched to Apple's
iPhone Turkish keyboard read by the capture tool on iOS 26.5 and 27.2 (iPhone 17
Pro and iPhone 11):

- Layouts, in Apple's order: Türkçe - Q (Apple's default: qwertyuıopğü /
  asdfghjklşi / zxcvbnmöç, 12/11/9 keys, shift and delete narrowed to fit),
  Türkçe - F (fgğıodrnhpqw / uieaütkmlyş / jövcçzsbx, a new
  KeyboardLetterLayout.turkishF offered only by Turkish, as Dvorak is
  English's) and QWERTY – Türkçe (plain QWERTY, Turkish letters held after
  their base, ı on I). Hex's letter rows match Apple's caps on both phones.
- Holds: Apple's (a â; i î ï ì í į ī; o ô œ ò ó õ ø ō; u û ù ú ū; s ß ś š;
  c ć č), the 123 page's $ holding ₺ second; pages otherwise English's.
- Case: KeyboardLanguage.caseLocale is tr for Turkish only, with uppercased,
  lowercased and capitalizingFirst. Shift and caps lock (keycaps and typed),
  held options in capitals, swipe output, case matching (matchCase now has an
  instance form in the engine's language), text replacements, vocabulary
  completion and spelling, Add to vocabulary, and a Turkish dictation's
  Polished/Casual/Notes capitals and Lowercase use it; every other language,
  English beside Turkish included, keeps Swift's rules exactly.
- No dictionary: the simulators' tr_TR rejects gibberish but calls "merhaba",
  "kitap", "teşekkür" typos ("kitap" -> "kitar"), so Turkish has no spell-check
  candidates and dictation's word check returns none for tr; it types as typed.
- Dictation: DictationTranscriber lists tr-TR on both simulators; the keys
  follow it as other languages'.

Verified: new cases in KeyboardLayoutTests, FullKeyboardEngineTests
(+TrackpadAndLanguages, +Layouts' haptics key), AutocorrectEngineTests and
TranscriptCleanupTests; Hex installed as a keyboard captured beside Apple's on
both runtimes and phones; full suite and code-shape --check in the PR.
2026-11-23 02:08:38 -05:00

45 lines
2.1 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import UIKit
/// Add to vocabulary from the strip: hold the word you typed (the strip's left slot) and the
/// strip offers it; the chip adds it to Hex's vocabulary list (`CustomVocabularySettings`,
/// the one Settings › Keyboard › Vocabulary and Settings › Dictation edit), which the keys
/// then never autocorrect away, complete and swipe.
@MainActor
extension FullKeyboardView {
func offerVocabulary(_ suggestion: KeyboardSuggestion) {
var word = suggestion.replacement
// A capital only the sentence's start gave it ("Kubectl" opening a message) isn't its own.
if let first = word.first, first.isUppercase, !word.dropFirst().contains(where: \.isUppercase),
AutocorrectEngine.startsSentence(before: engine.target.documentContextBeforeInput ?? "", token: word) {
word = engine.language.lowercased(String(first)) + word.dropFirst()
}
guard suggestion.kind == .keepLiteral, engine.autocorrect.vocabularyTerm(for: word) == nil,
VocabularySpelling.normalizedKey(word).count >= 2 else { return }
typingLog?.ui("vocabulary_offer")
selectionFeedback()
vocabularyOffer = word
refreshStrip()
}
var vocabularyNotice: KeyboardStripNotice? {
guard let word = vocabularyOffer else { return nil }
return KeyboardStripNotice(
title: "“\(word)”",
detail: String(localized: "Never autocorrected"),
button: String(localized: "Add to vocabulary")
)
}
/// Saves `word` in the App Group (kept for this session too where the keyboard can't
/// write there, without Full Access) and uses it at once.
func addToVocabulary(_ word: String) {
typingLog?.ui("vocabulary_add")
let settings = CustomVocabularySettings()
let terms = CustomVocabularySettings.sanitize(settings.terms + engine.autocorrect.vocabulary + [word])
settings.terms = terms
engine.autocorrect.setVocabulary(terms)
vocabularyOffer = nil
engine.refreshSuggestions()
refreshStrip()
}
}