* feat(editor): add setting to turn off spellcheck underlines Add a device-local "Underline spelling mistakes" switch to the editing preferences. The rich-text editor and the mobile plain-text editor now set spellcheck from this preference and update live when it changes. Defaults to enabled, so existing behavior is unchanged. Refs #468 * feat(i18n): add Polish as an in-app locale Add Polish (pl) across clients, mirroring how Japanese was added: - Shared: full pl catalog, locale matching for pl/pl-*, Polish memo templates and factory AI prompts, mobile editor strings, and Polish as an AI translation target and selection-translate chip. - Web: "Polski" in the language picker; the catalog is lazy-loaded in its own i18n-pl chunk and kept out of the PWA precache like ja. - Android: pl locale option, mobile-only strings, web-clip labels. Messages that only had an English branch now use English for every non-Chinese locale, so Japanese no longer falls back to Chinese there. - iOS: .polish UI language (pl-PL), pl argument for every t() call, pl in CFBundleLocalizations and Localizable.xcstrings. - Companion: accepts locale "pl" and detects Polish requests. - Browser extension: _locales/pl messages. - Marketing site: /pl/ pages, hreflang, sitemap, language switcher. - Google Play listing copy for pl-PL (manual publish only). * fix(ios): show the note editor in Polish and Japanese The iOS editor received every interface language except English as Chinese, so with Polish or Japanese selected its toolbar and image gallery controls were labeled in Chinese. Pass Polish and Japanese through to the embedded editor, label its toolbar and the shared image gallery controls in both languages, and rebuild the checked-in EditorBundle. The Android editor uses the same gallery labels. Also translate the last iOS strings that had no Polish text: the follow-system language label, note created/updated times and the current-device marker. Refs #473 * fix(companion): recognize Polish typed without diacritics Requests in Latin letters without Polish diacritics were always treated as English, so with a Polish interface "Napisz plan na jutro" got an English reply. With a Polish interface, such text is now told apart by common English and Polish words; when it is still unclear, the recent conversation and then the interface language decide. Other interface languages keep treating Latin text as English. Refs #473 * chore(ios): regenerate the Xcode project for Polish Run xcodegen so the shipped Info.plist lists Polish in CFBundleLocalizations and the project knows the pl region. The hand-written AiDirectStream.swift entries are replaced by the IDs xcodegen generates. MARKETING_VERSION and CURRENT_PROJECT_VERSION stay in the project file because the release script and Xcode Cloud update them there. Refs #473 * i18n(pl): translate the sidebar shortcut, desktop menus and video scope Add Polish for features that reached main while this branch was open: the show/hide sidebar shortcut label, the desktop application and editing context menus, and the new "ai:generate" MCP scope. The desktop menus switch to Polish for pl and pl-* locales; other locales are unchanged. Refs #473
168 lines
5.9 KiB
Swift
168 lines
5.9 KiB
Swift
import Foundation
|
|
import Observation
|
|
import SwiftUI
|
|
|
|
enum AppUILanguage: String {
|
|
case chinese
|
|
case english
|
|
case japanese
|
|
case polish
|
|
}
|
|
|
|
enum AppUILocale {
|
|
/// Unmatched system languages use English, not Simplified Chinese.
|
|
static func language(preferenceCode: String, systemLanguageCode: String?) -> AppUILanguage {
|
|
switch preferenceCode {
|
|
case "en-US": return .english
|
|
case "zh-CN": return .chinese
|
|
case "ja": return .japanese
|
|
case "pl": return .polish
|
|
default:
|
|
let code = (systemLanguageCode ?? "").lowercased()
|
|
if code.isEmpty { return .english }
|
|
if code.hasPrefix("zh") { return .chinese }
|
|
if code.hasPrefix("ja") { return .japanese }
|
|
if code.hasPrefix("pl") { return .polish }
|
|
return .english
|
|
}
|
|
}
|
|
|
|
static func usesEnglish(preferenceCode: String, systemLanguageCode: String?) -> Bool {
|
|
language(preferenceCode: preferenceCode, systemLanguageCode: systemLanguageCode) == .english
|
|
}
|
|
}
|
|
|
|
@Observable
|
|
@MainActor
|
|
final class PreferencesStore {
|
|
private let defaults: UserDefaults
|
|
|
|
/// system | zh-CN | en-US | ja | pl — matches Android locale preference.
|
|
var localeCode: String {
|
|
didSet { defaults.set(localeCode, forKey: Keys.locale) }
|
|
}
|
|
|
|
var useCompression: Bool {
|
|
didSet { defaults.set(useCompression, forKey: Keys.compression) }
|
|
}
|
|
|
|
/// Parent notebooks keep listing their sub-notebooks' notes unless turned off.
|
|
var showDescendantNotes: Bool {
|
|
didSet { defaults.set(showDescendantNotes, forKey: Keys.showDescendantNotes) }
|
|
}
|
|
|
|
/// system | light | dark
|
|
var theme: String {
|
|
didSet { defaults.set(theme, forKey: Keys.theme) }
|
|
}
|
|
|
|
var listDensity: ListDensity {
|
|
didSet { defaults.set(listDensity.rawValue, forKey: Keys.density) }
|
|
}
|
|
|
|
var aiAssistantLastActionStore: AiAssistantLastActionStore {
|
|
didSet { persistAiAssistantLastAction() }
|
|
}
|
|
|
|
init(defaults: UserDefaults = .standard) {
|
|
self.defaults = defaults
|
|
self.localeCode = defaults.string(forKey: Keys.locale) ?? "system"
|
|
self.useCompression = defaults.object(forKey: Keys.compression) as? Bool ?? true
|
|
self.showDescendantNotes = defaults.object(forKey: Keys.showDescendantNotes) as? Bool ?? true
|
|
self.theme = defaults.string(forKey: Keys.theme) ?? "system"
|
|
let densityRaw = defaults.string(forKey: Keys.density) ?? ListDensity.preview.rawValue
|
|
// Migrate legacy "comfortable" → preview
|
|
if densityRaw == "comfortable" {
|
|
self.listDensity = .preview
|
|
} else {
|
|
self.listDensity = ListDensity(rawValue: densityRaw) ?? .preview
|
|
}
|
|
self.aiAssistantLastActionStore = Self.decodeAiAssistantLastActionStore(defaults.string(forKey: Keys.aiAssistantLastAction))
|
|
}
|
|
|
|
var resolvedLocale: Locale {
|
|
switch localeCode {
|
|
case "zh-CN": return Locale(identifier: "zh-Hans")
|
|
case "en-US": return Locale(identifier: "en-US")
|
|
case "ja": return Locale(identifier: "ja-JP")
|
|
case "pl": return Locale(identifier: "pl-PL")
|
|
default: return .autoupdatingCurrent
|
|
}
|
|
}
|
|
|
|
var uiLanguage: AppUILanguage {
|
|
AppUILocale.language(
|
|
preferenceCode: localeCode,
|
|
systemLanguageCode: Locale.autoupdatingCurrent.language.languageCode?.identifier
|
|
)
|
|
}
|
|
|
|
/// Leftover two-way UI branches: Japanese and Polish must not fall through to Chinese.
|
|
var isEnglish: Bool { uiLanguage != .chinese }
|
|
|
|
var apiLocale: String {
|
|
switch uiLanguage {
|
|
case .english: return "en-US"
|
|
case .japanese: return "ja"
|
|
case .polish: return "pl"
|
|
case .chinese: return "zh-CN"
|
|
}
|
|
}
|
|
|
|
var colorScheme: ColorScheme? {
|
|
switch theme {
|
|
case "light": return .light
|
|
case "dark": return .dark
|
|
default: return nil
|
|
}
|
|
}
|
|
|
|
func t(_ zh: String, en: String, ja: String? = nil, pl: String? = nil) -> String {
|
|
switch uiLanguage {
|
|
case .english: return en
|
|
case .japanese: return ja ?? en
|
|
case .polish: return pl ?? en
|
|
case .chinese: return zh
|
|
}
|
|
}
|
|
|
|
func lastAiAssistantAction(isSelection: Bool) -> AiAssistantLastActionPreference? {
|
|
isSelection ? aiAssistantLastActionStore.selected : aiAssistantLastActionStore.wholeNote
|
|
}
|
|
|
|
func setLastAiAssistantAction(_ preference: AiAssistantLastActionPreference, isSelection: Bool) {
|
|
if isSelection {
|
|
aiAssistantLastActionStore.selected = preference
|
|
} else {
|
|
aiAssistantLastActionStore.wholeNote = preference
|
|
}
|
|
}
|
|
|
|
private func persistAiAssistantLastAction() {
|
|
if let data = try? JSONEncoder().encode(aiAssistantLastActionStore),
|
|
let raw = String(data: data, encoding: .utf8) {
|
|
defaults.set(raw, forKey: Keys.aiAssistantLastAction)
|
|
}
|
|
}
|
|
|
|
private static func decodeAiAssistantLastActionStore(_ raw: String?) -> AiAssistantLastActionStore {
|
|
guard let raw, let data = raw.data(using: .utf8) else { return AiAssistantLastActionStore() }
|
|
if let store = try? JSONDecoder().decode(AiAssistantLastActionStore.self, from: data) {
|
|
return store
|
|
}
|
|
if let legacy = try? JSONDecoder().decode(AiAssistantLastActionPreference.self, from: data) {
|
|
return AiAssistantLastActionStore(wholeNote: legacy)
|
|
}
|
|
return AiAssistantLastActionStore()
|
|
}
|
|
|
|
private enum Keys {
|
|
static let locale = "edgeever.ios.locale"
|
|
static let compression = "edgeever.ios.imageCompression"
|
|
static let showDescendantNotes = "edgeever.ios.showDescendantNotes"
|
|
static let theme = "edgeever.ios.theme"
|
|
static let density = "edgeever.ios.listDensity"
|
|
static let aiAssistantLastAction = "edgeever.aiAssistant.lastAction"
|
|
}
|
|
}
|