hex/ios/HEXMobile/SettingsPages.swift
Ryan Vogel e8d82f7101
iOS: Simplified Chinese interface for the app, widgets and permission prompts (#2083)
* iOS: make the app's interface strings localizable

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).

* iOS: Simplified Chinese (zh-Hans) interface

A Chinese-speaking TestFlight tester can't follow the English app. This
adds String Catalogs with English as the development language and
zh-Hans complete:

- HEXMobile/Localizable.xcstrings: 230 keys, 220 translated; 10 are
  marked do-not-translate (Hex, symbols, and the keyboard preview's
  sample chat). "· %lld steps" carries the English one/other plural.
- HEXWidgets/Localizable.xcstrings: the Live Activity, the Control
  Center control and the intents' titles (12 keys, 11 translated).
- HEXMobile/AppShortcuts.xcstrings: the Siri / Shortcuts phrases.
- HEXMobile/zh-Hans.lproj/InfoPlist.strings: the microphone and speech
  recognition prompts. The display name stays Hex.

With two localizations iOS follows the iPhone's language and offers
Settings › Apps › Hex › Language, so there's no in-app picker.

221 unique strings: 26 reuse Hex desktop's Simplified Chinese as is;
the rest are new, in Apple's Chinese iOS terms (键盘, 完全访问, 听写,
设置, 拷贝, 转录, Apple 智能). Five desktop strings were changed to those
terms: Copy/Copied (复制 -> 拷贝), Transcribing… (转写 -> 转录),
Clean up with Apple Intelligence (Apple 智能), and Set up (设置 ->
开始设置, so it isn't read as Settings). "Hex Keyboard" stays English
because it must match the keyboard's name in iOS Settings until the
keyboard is translated. Language names Hex shows in their own language
(the keyboard layouts) stay as they are. Acknowledgements keeps its
licence notices in English.

Not reviewed by a native speaker yet.

Verified on the Mac Studio (iOS 27.2 simulator, iPhone 16e, system
language zh-Hans): xcodebuild test passes (277 tests, 1 skipped); the
built app and widget extension carry zh-Hans.lproj; onboarding
(welcome, allow, try), the settings home and every settings page, the
setup sheet, typing logs, the Record typing logs alert, the error and
notice banners, the keyboard handoff screen, and iOS's microphone and
speech recognition prompts all show Chinese, without truncation; the
English app is unchanged.
2026-11-20 18:15:44 +00:00

398 lines
16 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 SwiftUI
/// Settings › Dictation: how Hex writes what you say, and the microphone.
struct DictationSettingsPage: View {
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@Bindable var dictation: DictationController
@State private var cleanupTagger = CleanupTaggerSettings().isEnabled
@State private var customVocabulary = CustomVocabularySettings().isEnabled
var body: some View {
SettingsPageScaffold(title: "Dictation") {
SettingsCard {
HStack(spacing: 12) {
SettingsRowLabel(title: String(localized: "Style"))
Spacer(minLength: 8)
Menu {
ForEach(DictationStyle.allCases, id: \.self) { candidate in
Button {
dictation.setStyle(candidate)
} label: {
if dictation.style == candidate {
Label(candidate.label, systemImage: "checkmark")
} else {
Text(candidate.label)
}
}
}
} label: {
SettingsMenuValue(value: dictation.style.label)
}
}
.padding(.horizontal, 16)
.frame(minHeight: 48)
DictationLanguageRow(dictation: dictation)
}
SettingsCard {
TranslateDictationRow()
.padding(.horizontal, 16)
.padding(.vertical, 10)
.frame(minHeight: 50)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Clean up what I say"),
detail: String(localized: "Drops ums, repeats and corrected words"),
isOn: $cleanupTagger
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Custom vocabulary"),
detail: String(localized: "Spell names and terms your way"),
isOn: $customVocabulary
)
if customVocabulary {
CustomVocabularyEditor()
.padding(.horizontal, 16)
.padding(.top, 2)
.padding(.bottom, 14)
}
}
SettingsCard {
HStack(spacing: 12) {
SettingsRowLabel(title: String(localized: "Keep mic warm"))
Spacer(minLength: 8)
SettingsSegments(
items: WarmSessionDuration.allCases,
selected: dictation.warmDuration,
label: \.shortLabel,
onSelect: { duration in
withAnimation(HexMotion.settleAnimation(reduceMotion: reduceMotion)) {
dictation.selectWarmDuration(duration)
}
}
)
}
.padding(.horizontal, 16)
.frame(minHeight: 50)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Always use iPhone microphone"),
detail: String(localized: "Keeps music playing and starts faster"),
isOn: Binding(
get: { !dictation.allowBluetoothMic },
set: { dictation.setAllowBluetoothMic(!$0) }
)
)
}
}
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: customVocabulary)
.onChange(of: cleanupTagger) { _, enabled in
CleanupTaggerSettings().isEnabled = enabled
}
.onChange(of: customVocabulary) { _, enabled in
CustomVocabularySettings().isEnabled = enabled
}
.onAppear {
cleanupTagger = CleanupTaggerSettings().isEnabled
customVocabulary = CustomVocabularySettings().isEnabled
}
}
}
/// Which keyboard Hex shows: the full keyboard (letters, with a Hex key to dictate) or the
/// dictation bar. Stored as `FullKeyboardSettings.isEnabled`.
private enum KeyboardChoice: CaseIterable {
case full
case dictationBar
var label: String {
switch self {
case .full: String(localized: "Full")
case .dictationBar: String(localized: "Dictation bar")
}
}
}
/// Settings › Keyboard: Full or Dictation bar, the full keyboard's rows (only while it's
/// chosen), and haptics, which the dictation bar uses too.
struct KeyboardSettingsPage: View {
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@State private var fullKeyboard = FullKeyboardSettings().isEnabled
@State private var autocorrect = FullKeyboardSettings().autocorrect
@State private var keyPopups = FullKeyboardSettings().keyPopups
@State private var haptics = FullKeyboardSettings().haptics
@State private var practiceText = ""
var body: some View {
SettingsPageScaffold(title: "Keyboard") {
SettingsCard {
HStack(spacing: 12) {
SettingsRowLabel(title: String(localized: "Keyboard"))
Spacer(minLength: 8)
SettingsSegments(
items: KeyboardChoice.allCases,
selected: fullKeyboard ? .full : .dictationBar,
label: \.label,
onSelect: { choice in
fullKeyboard = choice == .full
}
)
}
.padding(.horizontal, 16)
.frame(minHeight: 50)
if fullKeyboard {
KeyboardLayoutRow()
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Autocorrect"),
detail: String(localized: "Fixes typos when you press space"),
isOn: $autocorrect
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Key pop-ups"),
detail: String(localized: "Shows the letter above your finger"),
isOn: $keyPopups
)
}
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Haptics"),
detail: String(localized: "A light tap as you press Hex's keys"),
isOn: $haptics
)
}
TextField("Test keyboard…", text: $practiceText, axis: .vertical)
.font(.system(size: 15))
.foregroundStyle(HexTheme.textBase)
.lineLimit(1...4)
.padding(.horizontal, 16)
.padding(.vertical, 13)
.background(
HexTheme.bgBase,
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
)
}
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: fullKeyboard)
.onChange(of: fullKeyboard) { _, enabled in
FullKeyboardSettings().isEnabled = enabled
}
.onChange(of: autocorrect) { _, enabled in
FullKeyboardSettings().autocorrect = enabled
}
.onChange(of: keyPopups) { _, enabled in
FullKeyboardSettings().keyPopups = enabled
}
.onChange(of: haptics) { _, enabled in
FullKeyboardSettings().haptics = enabled
}
.onAppear {
fullKeyboard = FullKeyboardSettings().isEnabled
autocorrect = FullKeyboardSettings().autocorrect
keyPopups = FullKeyboardSettings().keyPopups
haptics = FullKeyboardSettings().haptics
}
}
}
/// Settings › Privacy: what Hex keeps about how you type, all of it on this iPhone, and
/// under Advanced the typing logs you can record to export.
struct PrivacySettingsPage: View {
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@State private var learnTyping = TypingJournalSettings().isEnabled
@State private var typingLogs = TypingLogSettings().isEnabled
@State private var showTypingLogs = false
@State private var confirmingTypingLogs = SettingsSnapshotFixture.confirmsTypingLogs
var body: some View {
SettingsPageScaffold(title: "Privacy") {
HStack(spacing: 7) {
Image(systemName: "lock.fill")
.font(.system(size: 11, weight: .medium))
Text("Everything stays on this iPhone")
.font(.system(size: 13))
}
.foregroundStyle(HexTheme.textMuted)
.padding(.horizontal, 16)
.padding(.bottom, 2)
SettingsCard {
// Not only for the full keyboard: it also learns from dictations the
// dictation bar inserts.
SettingsToggleRow(
title: String(localized: "Learn how I type"),
detail: String(localized: "Learns from taps and the words you fix"),
isOn: $learnTyping
)
if learnTyping {
SettingsDivider()
TypingInsightsView()
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 16)
.padding(.vertical, 12)
}
}
SettingsSectionHeader(title: "Advanced")
SettingsCard {
// Apart from Learn how I type: this keeps everything, to export and train on.
// Turning it on asks first (App Review 2.5.14); turning it off doesn't.
SettingsToggleRow(
title: String(localized: "Record typing logs"),
detail: String(localized: "Records taps and the text you type for 14 days, on this iPhone, to export. Off by default."),
isOn: Binding(
get: { typingLogs },
set: { on in
if on {
confirmingTypingLogs = true
} else {
typingLogs = false
}
}
)
)
.alert("Record typing logs?", isPresented: $confirmingTypingLogs) {
Button("Cancel", role: .cancel) {}
Button("Turn On") {
typingLogs = true
}
} message: {
Text("Hex's keyboard will record each tap and the text you type or dictate with it, including the text around the cursor, for 14 days. The logs stay on this iPhone for you to export or delete. Password, code and card fields are never recorded.")
}
if typingLogs {
SettingsDivider()
Button {
showTypingLogs = true
} label: {
SettingsLinkLabel(title: String(localized: "Typing logs"))
}
.buttonStyle(.plain)
}
}
}
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: learnTyping)
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: typingLogs)
.sheet(isPresented: $showTypingLogs) {
TypingLogsView()
}
.onChange(of: learnTyping) { _, enabled in
TypingJournalSettings().isEnabled = enabled
}
.onChange(of: typingLogs) { _, enabled in
TypingLogSettings().isEnabled = enabled
}
.onAppear {
learnTyping = TypingJournalSettings().isEnabled
typingLogs = TypingLogSettings().isEnabled
}
}
}
/// Settings › Experiments: unfinished features, off until turned on. They live in the App
/// Group so the keyboard reads them too.
struct ExperimentsSettingsPage: View {
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@State private var emoji = FullKeyboardSettings().emoji
@State private var emojiHistoryEmpty = EmojiUsageStore().isEmpty
@State private var spatialAutocorrect = FullKeyboardSettings().spatialAutocorrect
@State private var appleIntelligenceCleanup = AppleIntelligenceCleanupSettings().isEnabled
@State private var cleanupAvailability = AppleIntelligenceCleanupAvailability.current
var body: some View {
SettingsPageScaffold(title: "Experiments") {
SettingsCard {
EmojiExperimentRows(emoji: $emoji, historyEmpty: $emojiHistoryEmpty)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Spatial autocorrect"),
detail: FullKeyboardSettings().isEnabled && FullKeyboardSettings().autocorrect
? String(localized: "Reads where your taps land to fix typos, in English and Spanish")
: String(localized: "Needs the full keyboard with Autocorrect on"),
isOn: $spatialAutocorrect
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Clean up with Apple Intelligence"),
detail: cleanupAvailability.reason ?? String(localized: "Fixes misheard words on device"),
isOn: $appleIntelligenceCleanup
)
.disabled(!cleanupAvailability.isAvailable)
}
}
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: emoji)
.onChange(of: appleIntelligenceCleanup) { _, enabled in
AppleIntelligenceCleanupSettings().isEnabled = enabled
}
.onChange(of: spatialAutocorrect) { _, enabled in
FullKeyboardSettings().spatialAutocorrect = enabled
}
.onAppear {
emoji = FullKeyboardSettings().emoji
emojiHistoryEmpty = EmojiUsageStore().isEmpty
spatialAutocorrect = FullKeyboardSettings().spatialAutocorrect
appleIntelligenceCleanup = AppleIntelligenceCleanupSettings().isEnabled
cleanupAvailability = AppleIntelligenceCleanupAvailability.current
}
}
}
/// Experiments › Emoji: the full keyboard's emoji key, and while it's on, Clear emoji history.
private struct EmojiExperimentRows: View {
@Binding var emoji: Bool
@Binding var historyEmpty: Bool
var body: some View {
SettingsToggleRow(
title: String(localized: "Emoji"),
detail: FullKeyboardSettings().isEnabled
? String(localized: "An emoji key with suggestions as you type")
: String(localized: "Needs the full keyboard"),
isOn: $emoji
)
.onChange(of: emoji) { _, enabled in
FullKeyboardSettings().emoji = enabled
}
if emoji {
SettingsDivider()
Button {
EmojiUsageStore().clear()
historyEmpty = true
} label: {
Text("Clear emoji history")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(historyEmpty ? HexTheme.textFaint : HexTheme.textBase)
.frame(maxWidth: .infinity, minHeight: 50, alignment: .leading)
.padding(.horizontal, 16)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.disabled(historyEmpty)
}
}
}