Skip to content

Screenshots, hung out to dry. A tiny native macOS app that hangs every screenshot on a line at the top of your screen.

Swift

Translations in .strings files, one folder per language

Alejandro Buján4d45d7a54896
diff --git a/Package.swift b/Package.swift
index 61de070..3d927e3 100644
--- a/Package.swift
+++ b/Package.swift
@@ -5,6 +5,8 @@ let package = Package(
name: "Tendedero",
platforms: [.macOS(.v14)],
targets: [
- .executableTarget(name: "Tendedero", path: "Sources/Tendedero")
+ // Resources holds the translations. scripts/build-app.sh copies them
+ // into the app, so SwiftPM leaves them alone.
+ .executableTarget(name: "Tendedero", path: "Sources/Tendedero", exclude: ["Resources"])
]
)
diff --git a/README.md b/README.md
index 1387995..bf04e49 100644
--- a/README.md
+++ b/README.md
@@ -128,6 +128,9 @@ Every image here, the icon included, is drawn in code by
`scripts/make-icon.swift` and `scripts/make-readme-art.swift`.
`scripts/make-dmg.sh` builds the disk image for releases.
+Translations live in `Sources/Tendedero/Resources`, one `.lproj` folder per
+language. `swift scripts/check-strings.swift` checks that none is missing.
+
</details>
<br>
diff --git a/Sources/Tendedero/AppDelegate.swift b/Sources/Tendedero/AppDelegate.swift
index 467ff72..280d780 100644
--- a/Sources/Tendedero/AppDelegate.swift
+++ b/Sources/Tendedero/AppDelegate.swift
@@ -147,13 +147,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
private func offerInbox() {
Inbox.wasOffered = true
let alert = NSAlert()
- alert.messageText = L("Let Tendedero handle your screenshots?",
- "¿Quieres que Tendedero se encargue de tus capturas?")
+ alert.messageText = L("Let Tendedero handle your screenshots?")
alert.informativeText = L(
- "Screenshots will hang on the line the instant you take them, without the floating thumbnail, and will not pile up on your Desktop. Drag one to a folder to keep it, or discard it with the cross. You can turn this off from the menu bar, and your settings come back when Tendedero quits.",
- "Las capturas se colgarán al instante, sin la miniatura flotante, y no se acumularán en el Escritorio. Arrastra una a una carpeta para guardarla, o descártala con la cruz. Puedes desactivarlo desde la barra de menús, y tus ajustes vuelven a ser los de antes al salir de Tendedero.")
- alert.addButton(withTitle: L("Turn on", "Activar"))
- alert.addButton(withTitle: L("Not now", "Ahora no"))
+ "Screenshots will hang on the line the instant you take them, without the floating thumbnail, and will not pile up on your Desktop. Drag one to a folder to keep it, or discard it with the cross. You can turn this off from the menu bar, and your settings come back when Tendedero quits.")
+ alert.addButton(withTitle: L("Turn on"))
+ alert.addButton(withTitle: L("Not now"))
if let icon = NSImage(named: "Tendedero") ?? NSApp.applicationIconImage { alert.icon = icon }
NSApp.activate(ignoringOtherApps: true)
if alert.runModal() == .alertFirstButtonReturn { setInbox(true) }
@@ -460,50 +458,48 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
func menuNeedsUpdate(_ menu: NSMenu) {
menu.removeAllItems()
- let toggleItem = ClosureMenuItem(isRevealed ? L("Hide line", "Ocultar tendedero")
- : L("Show line", "Mostrar tendedero")) { [weak self] in
+ let toggleItem = ClosureMenuItem(isRevealed ? L("Hide line") : L("Show line")) { [weak self] in
self?.toggle()
}
toggleItem.keyEquivalent = "t"
toggleItem.keyEquivalentModifierMask = [.control, .option]
menu.addItem(toggleItem)
- let clearItem = ClosureMenuItem(L("Take everything down", "Descolgar todo")) { [weak self] in
+ let clearItem = ClosureMenuItem(L("Take everything down")) { [weak self] in
self?.line.clear()
}
clearItem.isEnabled = line.liveCount > 0
menu.addItem(clearItem)
- let inbox = ClosureMenuItem(L("Handle screenshots", "Encargarse de las capturas")) { [weak self] in
+ let inbox = ClosureMenuItem(L("Handle screenshots")) { [weak self] in
self?.setInbox(!Inbox.isEnabled)
}
inbox.state = Inbox.isEnabled ? .on : .off
- inbox.toolTip = L("Screenshots hang instantly and skip the Desktop",
- "Las capturas se cuelgan al instante y no pasan por el Escritorio")
+ inbox.toolTip = L("Screenshots hang instantly and skip the Desktop")
menu.addItem(inbox)
- menu.addItem(ClosureMenuItem(L("Open screenshots folder", "Abrir carpeta de capturas")) { [weak self] in
+ menu.addItem(ClosureMenuItem(L("Open screenshots folder")) { [weak self] in
guard let self else { return }
NSWorkspace.shared.open(self.watcher.folder)
})
menu.addItem(.separator())
- let sound = ClosureMenuItem(L("Sounds", "Sonidos")) { [weak self] in
+ let sound = ClosureMenuItem(L("Sounds")) { [weak self] in
guard let self else { return }
self.line.soundOn.toggle()
}
sound.state = line.soundOn ? .on : .off
menu.addItem(sound)
- let login = ClosureMenuItem(L("Open at login", "Abrir al iniciar sesión")) {
+ let login = ClosureMenuItem(L("Open at login")) {
AppDelegate.toggleLaunchAtLogin()
}
login.state = SMAppService.mainApp.status == .enabled ? .on : .off
menu.addItem(login)
menu.addItem(.separator())
- menu.addItem(ClosureMenuItem(L("Quit Tendedero", "Salir de Tendedero"), key: "q") {
+ menu.addItem(ClosureMenuItem(L("Quit Tendedero"), key: "q") {
NSApp.terminate(nil)
})
}
@@ -517,9 +513,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
}
} catch {
let alert = NSAlert()
- alert.messageText = L("Could not change the login setting", "No se pudo cambiar el inicio de sesión")
- alert.informativeText = L("Move Tendedero to the Applications folder and try again.",
- "Mueve Tendedero a la carpeta Aplicaciones y vuelve a intentarlo.")
+ alert.messageText = L("Could not change the login setting")
+ alert.informativeText = L("Move Tendedero to the Applications folder and try again.")
NSApp.activate(ignoringOtherApps: true)
alert.runModal()
}
diff --git a/Sources/Tendedero/GrabArea.swift b/Sources/Tendedero/GrabArea.swift
index eabab21..2d6c4bf 100644
--- a/Sources/Tendedero/GrabArea.swift
+++ b/Sources/Tendedero/GrabArea.swift
@@ -43,20 +43,20 @@ struct GrabArea: NSViewRepresentable {
view.onPressChange = { pressed in line.pressedID = pressed ? id : nil }
view.menuProvider = {
let menu = NSMenu()
- menu.addItem(ClosureMenuItem(L("Copy", "Copiar")) { line.copy(id) })
- menu.addItem(ClosureMenuItem(L("Open", "Abrir")) { line.open(id) })
- menu.addItem(ClosureMenuItem(L("Markup", "Marcación")) { line.markup(id) })
- menu.addItem(ClosureMenuItem(L("Show in Finder", "Mostrar en Finder")) { line.reveal(id) })
+ menu.addItem(ClosureMenuItem(L("Copy")) { line.copy(id) })
+ menu.addItem(ClosureMenuItem(L("Open")) { line.open(id) })
+ menu.addItem(ClosureMenuItem(L("Markup")) { line.markup(id) })
+ menu.addItem(ClosureMenuItem(L("Show in Finder")) { line.reveal(id) })
let inInbox = line.isInInbox(id)
if inInbox {
- menu.addItem(ClosureMenuItem(L("Save to Desktop", "Guardar en el Escritorio")) { line.saveToDesktop(id) })
+ menu.addItem(ClosureMenuItem(L("Save to Desktop")) { line.saveToDesktop(id) })
}
menu.addItem(.separator())
if inInbox {
- menu.addItem(ClosureMenuItem(L("Discard", "Descartar")) { line.discard(id) })
+ menu.addItem(ClosureMenuItem(L("Discard")) { line.discard(id) })
} else {
- menu.addItem(ClosureMenuItem(L("Take down", "Descolgar")) { line.discard(id) })
- menu.addItem(ClosureMenuItem(L("Move to Trash", "Mover a la Papelera")) { line.trash(id) })
+ menu.addItem(ClosureMenuItem(L("Take down")) { line.discard(id) })
+ menu.addItem(ClosureMenuItem(L("Move to Trash")) { line.trash(id) })
}
return menu
}
diff --git a/Sources/Tendedero/LineView.swift b/Sources/Tendedero/LineView.swift
index 8892255..8304b5b 100644
--- a/Sources/Tendedero/LineView.swift
+++ b/Sources/Tendedero/LineView.swift
@@ -61,7 +61,7 @@ struct LineView: View {
private struct Hint: View {
var body: some View {
- Text(L("Take a screenshot and it will hang here", "Haz una captura y se quedará colgada aquí"))
+ Text(L("Take a screenshot and it will hang here"))
.font(.system(size: 12, weight: .medium, design: .rounded))
.foregroundStyle(.secondary)
.padding(.horizontal, 12)
diff --git a/Sources/Tendedero/Localization.swift b/Sources/Tendedero/Localization.swift
index 8cd02bf..8b6f9a5 100644
--- a/Sources/Tendedero/Localization.swift
+++ b/Sources/Tendedero/Localization.swift
@@ -1,9 +1,11 @@
import Foundation
-private let isSpanish = Locale.preferredLanguages.first?.hasPrefix("es") ?? false
-
-/// Tiny two-language helper. The app has a handful of strings, so a full
-/// .strings setup would be more ceremony than content.
-func L(_ english: String, _ spanish: String) -> String {
- isSpanish ? spanish : english
+/// Looks up text in `Resources/<language>.lproj/Localizable.strings`, keyed by
+/// the English text itself. macOS picks the language from the user's whole
+/// list of preferred languages, and anything missing falls back to English.
+///
+/// The folders are copied into the app by `scripts/build-app.sh`. Running the
+/// bare binary, outside the app, shows English.
+func L(_ english: String) -> String {
+ NSLocalizedString(english, comment: "")
}
diff --git a/Sources/Tendedero/PeggedView.swift b/Sources/Tendedero/PeggedView.swift
index 344ee4e..ee6eeab 100644
--- a/Sources/Tendedero/PeggedView.swift
+++ b/Sources/Tendedero/PeggedView.swift
@@ -88,7 +88,7 @@ struct PeggedView: View {
.overlay(GrabArea(item: item, line: line))
.overlay(alignment: .bottom) {
if copied {
- Label(L("Copied", "Copiado"), systemImage: "checkmark")
+ Label(L("Copied"), systemImage: "checkmark")
.font(.system(size: 11, weight: .semibold))
.foregroundStyle(.primary)
.padding(.horizontal, 10)
diff --git a/Sources/Tendedero/Resources/en.lproj/Localizable.strings b/Sources/Tendedero/Resources/en.lproj/Localizable.strings
new file mode 100644
index 0000000..49842ba
--- /dev/null
+++ b/Sources/Tendedero/Resources/en.lproj/Localizable.strings
@@ -0,0 +1,36 @@
+/* English. Each key is the English text exactly as written in L("...") in
+ the code. Every language has the same keys; run
+ swift scripts/check-strings.swift to check. */
+
+/* AppDelegate */
+"Let Tendedero handle your screenshots?" = "Let Tendedero handle your screenshots?";
+"Screenshots will hang on the line the instant you take them, without the floating thumbnail, and will not pile up on your Desktop. Drag one to a folder to keep it, or discard it with the cross. You can turn this off from the menu bar, and your settings come back when Tendedero quits." = "Screenshots will hang on the line the instant you take them, without the floating thumbnail, and will not pile up on your Desktop. Drag one to a folder to keep it, or discard it with the cross. You can turn this off from the menu bar, and your settings come back when Tendedero quits.";
+"Turn on" = "Turn on";
+"Not now" = "Not now";
+"Hide line" = "Hide line";
+"Show line" = "Show line";
+"Take everything down" = "Take everything down";
+"Handle screenshots" = "Handle screenshots";
+"Screenshots hang instantly and skip the Desktop" = "Screenshots hang instantly and skip the Desktop";
+"Open screenshots folder" = "Open screenshots folder";
+"Sounds" = "Sounds";
+"Open at login" = "Open at login";
+"Quit Tendedero" = "Quit Tendedero";
+"Could not change the login setting" = "Could not change the login setting";
+"Move Tendedero to the Applications folder and try again." = "Move Tendedero to the Applications folder and try again.";
+
+/* GrabArea */
+"Copy" = "Copy";
+"Open" = "Open";
+"Markup" = "Markup";
+"Show in Finder" = "Show in Finder";
+"Save to Desktop" = "Save to Desktop";
+"Discard" = "Discard";
+"Take down" = "Take down";
+"Move to Trash" = "Move to Trash";
+
+/* LineView */
+"Take a screenshot and it will hang here" = "Take a screenshot and it will hang here";
+
+/* PeggedView */
+"Copied" = "Copied";
diff --git a/Sources/Tendedero/Resources/es.lproj/Localizable.strings b/Sources/Tendedero/Resources/es.lproj/Localizable.strings
new file mode 100644
index 0000000..5e6f768
--- /dev/null
+++ b/Sources/Tendedero/Resources/es.lproj/Localizable.strings
@@ -0,0 +1,34 @@
+/* Spanish. */
+
+/* AppDelegate */
+"Let Tendedero handle your screenshots?" = "¿Quieres que Tendedero se encargue de tus capturas?";
+"Screenshots will hang on the line the instant you take them, without the floating thumbnail, and will not pile up on your Desktop. Drag one to a folder to keep it, or discard it with the cross. You can turn this off from the menu bar, and your settings come back when Tendedero quits." = "Las capturas se colgarán al instante, sin la miniatura flotante, y no se acumularán en el Escritorio. Arrastra una a una carpeta para guardarla, o descártala con la cruz. Puedes desactivarlo desde la barra de menús, y tus ajustes vuelven a ser los de antes al salir de Tendedero.";
+"Turn on" = "Activar";
+"Not now" = "Ahora no";
+"Hide line" = "Ocultar tendedero";
+"Show line" = "Mostrar tendedero";
+"Take everything down" = "Descolgar todo";
+"Handle screenshots" = "Encargarse de las capturas";
+"Screenshots hang instantly and skip the Desktop" = "Las capturas se cuelgan al instante y no pasan por el Escritorio";
+"Open screenshots folder" = "Abrir carpeta de capturas";
+"Sounds" = "Sonidos";
+"Open at login" = "Abrir al iniciar sesión";
+"Quit Tendedero" = "Salir de Tendedero";
+"Could not change the login setting" = "No se pudo cambiar el inicio de sesión";
+"Move Tendedero to the Applications folder and try again." = "Mueve Tendedero a la carpeta Aplicaciones y vuelve a intentarlo.";
+
+/* GrabArea */
+"Copy" = "Copiar";
+"Open" = "Abrir";
+"Markup" = "Marcación";
+"Show in Finder" = "Mostrar en Finder";
+"Save to Desktop" = "Guardar en el Escritorio";
+"Discard" = "Descartar";
+"Take down" = "Descolgar";
+"Move to Trash" = "Mover a la Papelera";
+
+/* LineView */
+"Take a screenshot and it will hang here" = "Haz una captura y se quedará colgada aquí";
+
+/* PeggedView */
+"Copied" = "Copiado";
diff --git a/scripts/build-app.sh b/scripts/build-app.sh
index 04d2c62..88a5c49 100755
--- a/scripts/build-app.sh
+++ b/scripts/build-app.sh
@@ -48,6 +48,14 @@ done
iconutil -c icns "$ICONSET" -o "$APP/Contents/Resources/Tendedero.icns"
rm -rf "$WORK"
+# Translations: one folder per language, listed in Info.plist so macOS knows
+# which languages the app speaks.
+LANGUAGES=""
+for dir in Sources/Tendedero/Resources/*.lproj; do
+ cp -R "$dir" "$APP/Contents/Resources/"
+ LANGUAGES="$LANGUAGES<string>$(basename "$dir" .lproj)</string>"
+done
+
cat > "$APP/Contents/Info.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -61,6 +69,8 @@ cat > "$APP/Contents/Info.plist" <<PLIST
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>${VERSION}</string>
<key>CFBundleVersion</key><string>1</string>
+ <key>CFBundleDevelopmentRegion</key><string>en</string>
+ <key>CFBundleLocalizations</key><array>${LANGUAGES}</array>
<key>LSMinimumSystemVersion</key><string>14.0</string>
<key>LSUIElement</key><true/>
<key>NSHighResolutionCapable</key><true/>
diff --git a/scripts/check-strings.swift b/scripts/check-strings.swift
new file mode 100644
index 0000000..3d69228
--- /dev/null
+++ b/scripts/check-strings.swift
@@ -0,0 +1,49 @@
+// Checks the translations: every L("...") in the code has an entry in each
+// language, and no language keeps entries the code no longer uses.
+// Usage: swift scripts/check-strings.swift
+import Foundation
+
+let sources = URL(fileURLWithPath: "Sources/Tendedero")
+let resources = sources.appendingPathComponent("Resources")
+let fm = FileManager.default
+
+// Every L("...") call. A call that is not a plain string literal cannot be
+// checked, so it is reported too.
+var used = Set<String>()
+var problems: [String] = []
+let literal = try NSRegularExpression(pattern: #"\bL\(\s*"((?:[^"\\]|\\.)*)"\s*\)"#)
+let anyCall = try NSRegularExpression(pattern: #"\bL\("#)
+for case let file as URL in fm.enumerator(at: sources, includingPropertiesForKeys: nil)!
+where file.pathExtension == "swift" && file.lastPathComponent != "Localization.swift" {
+ let text = try String(contentsOf: file, encoding: .utf8)
+ let range = NSRange(text.startIndex..., in: text)
+ let literals = literal.matches(in: text, range: range)
+ for match in literals {
+ let key = String(text[Range(match.range(at: 1), in: text)!])
+ used.insert(key.replacingOccurrences(of: #"\""#, with: #"""#))
+ }
+ let calls = anyCall.numberOfMatches(in: text, range: range)
+ if calls != literals.count {
+ problems.append("\(file.lastPathComponent): \(calls - literals.count) L(...) call(s) without a plain string")
+ }
+}
+
+let languages = try fm.contentsOfDirectory(atPath: resources.path)
+ .filter { $0.hasSuffix(".lproj") }.sorted()
+for folder in languages {
+ let url = resources.appendingPathComponent(folder).appendingPathComponent("Localizable.strings")
+ guard let table = NSDictionary(contentsOf: url) as? [String: String] else {
+ problems.append("\(folder): Localizable.strings is missing or cannot be read")
+ continue
+ }
+ let keys = Set(table.keys)
+ for key in used.subtracting(keys).sorted() { problems.append("\(folder): missing \"\(key)\"") }
+ for key in keys.subtracting(used).sorted() { problems.append("\(folder): unused \"\(key)\"") }
+}
+
+if problems.isEmpty {
+ print("\(used.count) strings, all present in \(languages.map { $0.replacingOccurrences(of: ".lproj", with: "") }.joined(separator: ", "))")
+} else {
+ problems.forEach { print($0) }
+ exit(1)
+}