mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
Strings built as String values (status lines, menu and segment labels,
settings rows, errors, notices, shared model labels) never reached a
string table, so a translation couldn't replace them. They now go
through String(localized:), and the app's own small components that
only take literals (onboarding buttons and rows, page titles, section
headers, setup sheet rows) take LocalizedStringKey. English output is
unchanged.
- "1 step"/"N steps", "N event(s)" and "N dictation(s) learned" no
longer glue English words together; the plural lives in the catalog
or in two whole sentences, so other languages can order them.
- Where you tap off-centre names the eight directions as whole phrases
instead of joining "low" + " and " + "right".
- Language names in messages ("Russian isn't available...", "Use
English", "Paste in Spanish") follow Hex's interface language
(Locale.hexInterface, the bundle's preferred localization) instead of
always English. SpeechModelUnavailable.englishName is renamed
interfaceName. The keyboard has no translations yet, so it still says
English.
- project.yml turns on SWIFT_EMIT_LOC_STRINGS and
LOCALIZATION_PREFERS_STRING_CATALOGS so the compiler extracts these
strings for String Catalogs; without it, an export found only ~50 of
the app's ~230 strings.
Not touched: HEXKeyboard/ and the keyboard's views in
HEXShared/FullKeyboard and KeyboardSurface.swift.
Verified on the Mac Studio (iOS 27.2 simulator, iPhone 16e):
xcodebuild test passes, 277 tests (1 skipped), and the English app
renders as before (onboarding, settings home, Dictation, Privacy).
129 lines
4.3 KiB
Swift
129 lines
4.3 KiB
Swift
import SwiftUI
|
||
|
||
/// The custom vocabulary list shown under its switch in Settings › Dictation.
|
||
struct CustomVocabularyEditor: View {
|
||
private let settings = CustomVocabularySettings()
|
||
|
||
@State private var terms: [String] = []
|
||
@State private var draft = ""
|
||
@State private var notice: String?
|
||
|
||
private var isAtLimit: Bool {
|
||
terms.count >= CustomVocabularySettings.maxTermCount
|
||
}
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
ForEach(terms, id: \.self) { term in
|
||
HStack(spacing: 10) {
|
||
Text(term)
|
||
.font(.system(size: 14))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.lineLimit(1)
|
||
|
||
Spacer(minLength: 8)
|
||
|
||
Button {
|
||
remove(term)
|
||
} label: {
|
||
Image(systemName: "xmark")
|
||
.font(.system(size: 11, weight: .semibold))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.frame(width: 26, height: 26)
|
||
.background(HexTheme.layer02, in: Circle())
|
||
}
|
||
.buttonStyle(.plain)
|
||
.accessibilityLabel("Remove \(term)")
|
||
}
|
||
.padding(.leading, 12)
|
||
.padding(.trailing, 6)
|
||
.frame(minHeight: 36)
|
||
.background(
|
||
HexTheme.layer01,
|
||
in: RoundedRectangle(
|
||
cornerRadius: HexTheme.controlRadius,
|
||
style: .continuous
|
||
)
|
||
)
|
||
}
|
||
|
||
TextField("Add a word or phrase", text: $draft)
|
||
.font(.system(size: 14))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.textInputAutocapitalization(.never)
|
||
.autocorrectionDisabled()
|
||
.submitLabel(.done)
|
||
.onSubmit(add)
|
||
.onChange(of: draft) { _, _ in
|
||
notice = nil
|
||
}
|
||
.disabled(isAtLimit)
|
||
.padding(.horizontal, 12)
|
||
.frame(minHeight: 38)
|
||
.background(
|
||
HexTheme.layer01,
|
||
in: RoundedRectangle(
|
||
cornerRadius: HexTheme.controlRadius,
|
||
style: .continuous
|
||
)
|
||
)
|
||
.opacity(isAtLimit ? 0.5 : 1)
|
||
|
||
if isAtLimit {
|
||
Text("Up to 100 terms")
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
}
|
||
|
||
if let notice {
|
||
Text(notice)
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
|
||
Text("Fixes spelling, not words Hex mishears")
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
.onAppear {
|
||
terms = settings.terms
|
||
}
|
||
}
|
||
|
||
private func add() {
|
||
guard !isAtLimit else { return }
|
||
let candidate = draft.trimmingCharacters(in: .whitespacesAndNewlines)
|
||
guard !candidate.isEmpty else { return }
|
||
|
||
guard candidate.count <= CustomVocabularySettings.maxTermLength else {
|
||
notice = String(localized: "Too long")
|
||
return
|
||
}
|
||
let key = VocabularySpelling.normalizedKey(candidate)
|
||
guard key.count >= 2 else {
|
||
notice = String(localized: "Needs at least two letters or digits")
|
||
return
|
||
}
|
||
let isDuplicate = terms.contains {
|
||
VocabularySpelling.normalizedKey($0) == key
|
||
}
|
||
guard !isDuplicate else {
|
||
notice = String(localized: "Already in the list")
|
||
return
|
||
}
|
||
|
||
let updated = CustomVocabularySettings.sanitize(terms + [candidate])
|
||
terms = updated
|
||
settings.terms = updated
|
||
draft = ""
|
||
notice = nil
|
||
}
|
||
|
||
private func remove(_ term: String) {
|
||
terms.removeAll { $0 == term }
|
||
settings.terms = terms
|
||
notice = nil
|
||
}
|
||
}
|