From 81b52f867667f85223b77b2f4a6493f1e5fc25cc Mon Sep 17 00:00:00 2001 From: Kai Azim Date: Thu, 11 Jul 2024 14:42:23 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20Support=20localization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Loop/Localizable.xcstrings | 114 +++++++++++++++++- .../KeybindingsConfiguration.swift | 1 - Loop/Luminare/Theming/IconConfiguration.swift | 2 +- .../Utilities/RectangleTranslationLayer.swift | 2 +- .../Window Management/WindowAction+Port.swift | 43 ++++++- 5 files changed, 150 insertions(+), 12 deletions(-) diff --git a/Loop/Localizable.xcstrings b/Loop/Localizable.xcstrings index e4c0fda6..03837337 100644 --- a/Loop/Localizable.xcstrings +++ b/Loop/Localizable.xcstrings @@ -614,6 +614,17 @@ } } }, + "App icon is locked" : { + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Locked" + } + } + } + }, "Behavior" : { "localizations" : { "en-GB" : { @@ -1698,6 +1709,9 @@ } } } + }, + "Do you want to merge or erase existing keybinds?" : { + }, "Donate" : { "localizations" : { @@ -1819,6 +1833,28 @@ } } }, + "Error reading keybinds alert description" : { + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Make sure the file you selected is in the correct format." + } + } + } + }, + "Error reading keybinds alert title" : { + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Error Reading Keybinds" + } + } + } + }, "Excluded Apps" : { "localizations" : { "en-GB" : { @@ -1898,6 +1934,31 @@ } } } + }, + "Export empty keybinds alert description" : { + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "You can't export something that doesn't exist!" + } + } + } + }, + "Export empty keybinds alert title" : { + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "No Keybinds Have Been Set" + } + } + } + }, + "Export keybinds" : { + }, "External bar" : { "localizations" : { @@ -3322,9 +3383,56 @@ } } } + }, + "Import from Rectangle" : { + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Select Rectangle config file" + } + } + } + }, + "Import Keybinds" : { + }, "Import keybinds from Rectangle" : { + }, + "Import keybinds: cancel" : { + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Cancel" + } + } + } + }, + "Import keybinds: erase" : { + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Erase" + } + } + } + }, + "Import keybinds: merge" : { + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Merge" + } + } + } }, "Include development versions" : { "localizations" : { @@ -3689,9 +3797,6 @@ } } }, - "Locked" : { - "comment" : "App icon is locked" - }, "Locked icon message 1" : { "extractionState" : "extracted_with_value", "localizations" : { @@ -6164,6 +6269,9 @@ } } } + }, + "Select Loop keybinds file" : { + }, "Send Feedback" : { "localizations" : { diff --git a/Loop/Luminare/Settings/Keybindings/KeybindingsConfiguration.swift b/Loop/Luminare/Settings/Keybindings/KeybindingsConfiguration.swift index c4fa287b..5ceb76cd 100644 --- a/Loop/Luminare/Settings/Keybindings/KeybindingsConfiguration.swift +++ b/Loop/Luminare/Settings/Keybindings/KeybindingsConfiguration.swift @@ -5,7 +5,6 @@ // Created by Kai Azim on 2024-04-20. // -import Combine import Defaults import Luminare import SwiftUI diff --git a/Loop/Luminare/Theming/IconConfiguration.swift b/Loop/Luminare/Theming/IconConfiguration.swift index 46228ce8..fe1f3f72 100644 --- a/Loop/Luminare/Theming/IconConfiguration.swift +++ b/Loop/Luminare/Theming/IconConfiguration.swift @@ -164,7 +164,7 @@ struct IconVew: View { Text(nextUnlockCount == icon.unlockTime ? .init(localized: "Loops left to unlock new icon", defaultValue: "\(loopsLeft) Loops left") : - .init(localized: "Locked", comment: "App icon is locked") + .init(localized: "App icon is locked", defaultValue: "Locked") ) .font(.caption) .foregroundColor(.secondary) diff --git a/Loop/Utilities/RectangleTranslationLayer.swift b/Loop/Utilities/RectangleTranslationLayer.swift index 9b600fb6..dad0d181 100644 --- a/Loop/Utilities/RectangleTranslationLayer.swift +++ b/Loop/Utilities/RectangleTranslationLayer.swift @@ -58,7 +58,7 @@ enum RectangleTranslationLayer { /// Initiates the import process for the RectangleConfig.json file. static func importRectangleConfig() { let openPanel = NSOpenPanel() - openPanel.prompt = "Select Rectangle Config File" + openPanel.prompt = .init(localized: "Import from Rectangle", defaultValue: "Select Rectangle config file") openPanel.allowedContentTypes = [.json] // Presents a file open panel to the user. diff --git a/Loop/Window Management/WindowAction+Port.swift b/Loop/Window Management/WindowAction+Port.swift index 84e33ca0..15cd32e7 100644 --- a/Loop/Window Management/WindowAction+Port.swift +++ b/Loop/Window Management/WindowAction+Port.swift @@ -41,7 +41,16 @@ extension WindowAction { static func exportPrompt() { // Check if there are any keybinds to export. guard !Defaults[.keybinds].isEmpty else { - showAlert("No Keybinds Have Been Set", informativeText: "You can't export something that doesn't exist!") + showAlert( + .init( + localized: "Export empty keybinds alert title", + defaultValue: "No Keybinds Have Been Set" + ), + informativeText: .init( + localized: "Export empty keybinds alert description", + defaultValue: "You can't export something that doesn't exist!" + ) + ) return } @@ -63,7 +72,7 @@ extension WindowAction { guard let data = keybindsData.data(using: .utf8) else { return } let savePanel = NSSavePanel() savePanel.directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first - savePanel.title = "Export Keybinds" + savePanel.title = .init(localized: "Export keybinds") savePanel.nameFieldStringValue = "keybinds.json" savePanel.allowedContentTypes = [.json] @@ -80,7 +89,7 @@ extension WindowAction { /// Presents a prompt to import keybinds from a JSON file. static func importPrompt() { let openPanel = NSOpenPanel() - openPanel.title = "Select Loop Keybinds File" + openPanel.title = .init(localized: "Select Loop keybinds file") openPanel.allowedContentTypes = [.json] openPanel.beginSheetModal(for: NSApplication.shared.mainWindow!) { result in guard result == .OK, let selectedFileURL = openPanel.url else { return } @@ -101,7 +110,16 @@ extension WindowAction { let importedKeybinds = try decoder.decode([SavedWindowActionFormat].self, from: keybindsData) updateDefaults(with: importedKeybinds) } catch { - showAlert("Error Reading Keybinds", informativeText: "Make sure the file you selected is in the correct format.") + showAlert( + .init( + localized: "Error reading keybinds alert title", + defaultValue: "Error Reading Keybinds" + ), + informativeText: .init( + localized: "Error reading keybinds alert description", + defaultValue: "Make sure the file you selected is in the correct format." + ) + ) } } @@ -135,7 +153,15 @@ extension WindowAction { /// Presents a decision alert for how to handle imported keybinds. private static func showAlertForImportDecision(completion: @escaping (ImportDecision) -> ()) { - showAlert("Import Keybinds", informativeText: "Do you want to merge or erase existing keybinds?", buttons: ["Merge", "Erase", "Cancel"]) { response in + showAlert( + .init(localized: "Import Keybinds"), + informativeText: .init(localized: "Do you want to merge or erase existing keybinds?"), + buttons: [ + .init(localized: "Import keybinds: merge", defaultValue: "Merge"), + .init(localized: "Import keybinds: erase", defaultValue: "Erase"), + .init(localized: "Import keybinds: cancel", defaultValue: "Cancel") + ] + ) { response in switch response { case .alertFirstButtonReturn: completion(.merge) @@ -148,7 +174,12 @@ extension WindowAction { } /// Utility function to show an alert with a completion handler. - private static func showAlert(_ messageText: String, informativeText: String, buttons: [String] = [], completion: ((NSApplication.ModalResponse) -> ())? = nil) { + private static func showAlert( + _ messageText: String, + informativeText: String, + buttons: [String] = [], + completion: ((NSApplication.ModalResponse) -> ())? = nil + ) { let alert = NSAlert() alert.messageText = messageText alert.informativeText = informativeText