From 108b05c619b432f093e9cd64a15ce3bbc0e02840 Mon Sep 17 00:00:00 2001
From: Ariver <ar@MacBook-Air.local>
Date: Wed, 06 May 2026 18:25:40 +0800
Subject: [PATCH] checkpoint: v3.1.0 — 国际化:9语种 JSON 翻译文件 + Language 菜单 + L10n/tr()
---
Apptag/ApptagApp.swift | 56 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/Apptag/ApptagApp.swift b/Apptag/ApptagApp.swift
index 8edd2e1..640545d 100644
--- a/Apptag/ApptagApp.swift
+++ b/Apptag/ApptagApp.swift
@@ -24,7 +24,7 @@
private var isInEditMode = false // Suppress auto-dismiss during editing
func applicationDidFinishLaunching(_ notification: Notification) {
- // Use .accessory so the app appears in Force Quit (unlike LSUIElement)
+ L10n.setup()
NSApp.setActivationPolicy(.accessory)
setupMenuBar()
registerHotkey()
@@ -50,7 +50,7 @@
let menu = NSMenu()
menu.addItem(
NSMenuItem(
- title: "Show Apptag",
+ title: tr("menu.show"),
action: #selector(toggleOverlay),
keyEquivalent: ""
)
@@ -61,7 +61,7 @@
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "?"
let buildNumber = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "?"
let versionItem = NSMenuItem(
- title: "Version \(appVersion) (\(buildNumber))",
+ title: "\(tr("menu.version")) \(appVersion) (\(buildNumber))",
action: nil,
keyEquivalent: ""
)
@@ -70,16 +70,31 @@
menu.addItem(.separator())
let prefsItem = NSMenuItem(
- title: "Preferences...",
+ title: tr("menu.preferences"),
action: #selector(openPreferences),
keyEquivalent: ","
)
prefsItem.keyEquivalentModifierMask = .command
menu.addItem(prefsItem)
menu.addItem(.separator())
+
+ // Language submenu
+ let langMenu = NSMenu()
+ let currentLang = UserDefaults.standard.string(forKey: "appLanguage") ?? "en"
+ for (code, name) in L10n.supported {
+ let item = NSMenuItem(title: name, action: #selector(switchLanguage(_:)), keyEquivalent: "")
+ item.representedObject = code
+ item.state = (code == currentLang) ? .on : .off
+ langMenu.addItem(item)
+ }
+ let langItem = NSMenuItem(title: tr("menu.language"), action: nil, keyEquivalent: "")
+ langItem.submenu = langMenu
+ menu.addItem(langItem)
+
+ menu.addItem(.separator())
menu.addItem(
NSMenuItem(
- title: "Quit",
+ title: tr("menu.quit"),
action: #selector(NSApplication.terminate(_:)),
keyEquivalent: "q"
)
@@ -237,6 +252,13 @@
hideOverlay()
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
}
+
+ @objc private func switchLanguage(_ sender: NSMenuItem) {
+ guard let code = sender.representedObject as? String else { return }
+ L10n.switchTo(code)
+ // Rebuild menu to update checkmarks
+ setupMenuBar()
+ }
}
// MARK: - NSView-level backdrop dismiss (works even if SwiftUI rendering is slow)
@@ -319,6 +341,8 @@
@AppStorage("iconSize") private var iconSize: Double = 56
@AppStorage("tagPosition") private var tagPosition = "left"
@AppStorage("defaultGroupName") private var defaultGroupName = "Other"
+ @AppStorage("displayMode") private var displayMode = "flat"
+ @AppStorage("hideAppNames") private var hideAppNames = false
@State private var allApps: [AppInfo] = []
@State private var tagColors: [String: Int] = [:]
@@ -385,6 +409,20 @@
// Tab 1: General
Form {
Section {
+ LabeledContent("App list style:") {
+ Picker("", selection: $displayMode) {
+ Text("Flat").tag("flat")
+ Text("Container").tag("container")
+ }
+ .pickerStyle(.segmented)
+ .frame(width: 210)
+ }
+ Text("\"Flat\" shows apps directly. \"Container\" wraps each tag group in a rounded box.")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ }
+
+ Section {
LabeledContent("Tag position:") {
Picker("", selection: $tagPosition) {
Text("Left").tag("left")
@@ -412,8 +450,6 @@
Text("Adjust the size of group-name labels in the overlay.")
.font(.caption)
.foregroundStyle(.secondary)
- } header: {
- Text("Appearance")
}
Section {
@@ -429,8 +465,10 @@
Text("Icon display size. Grid columns adjust automatically.")
.font(.caption)
.foregroundStyle(.secondary)
- } header: {
- Text("Layout")
+ }
+
+ Section {
+ Toggle("Hide app names", isOn: $hideAppNames)
}
}
.tabItem { Label("General", systemImage: "gearshape") }
--
Gitblit v1.9.3