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).
164 lines
6.4 KiB
Swift
164 lines
6.4 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 String(localized: "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, Português, Русский, or Srpski (Latin).
|
||
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: String(localized: "Automatic"))
|
||
Divider()
|
||
ForEach(KeyboardLanguage.allCases, id: \.self) { language in
|
||
choice(language, title: language.displayName)
|
||
}
|
||
} label: {
|
||
LanguageMenuValue(value: setting?.displayName ?? String(localized: "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())
|
||
}
|
||
}
|