Skip to content

Commit

Permalink
🌐 Support localization
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Jul 11, 2024
1 parent 56a051e commit 81b52f8
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 12 deletions.
114 changes: 111 additions & 3 deletions Loop/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,17 @@
}
}
},
"App icon is locked" : {
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Locked"
}
}
}
},
"Behavior" : {
"localizations" : {
"en-GB" : {
Expand Down Expand Up @@ -1698,6 +1709,9 @@
}
}
}
},
"Do you want to merge or erase existing keybinds?" : {

},
"Donate" : {
"localizations" : {
Expand Down Expand Up @@ -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" : {
Expand Down Expand Up @@ -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" : {
Expand Down Expand Up @@ -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" : {
Expand Down Expand Up @@ -3689,9 +3797,6 @@
}
}
},
"Locked" : {
"comment" : "App icon is locked"
},
"Locked icon message 1" : {
"extractionState" : "extracted_with_value",
"localizations" : {
Expand Down Expand Up @@ -6164,6 +6269,9 @@
}
}
}
},
"Select Loop keybinds file" : {

},
"Send Feedback" : {
"localizations" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Kai Azim on 2024-04-20.
//

import Combine
import Defaults
import Luminare
import SwiftUI
Expand Down
2 changes: 1 addition & 1 deletion Loop/Luminare/Theming/IconConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Loop/Utilities/RectangleTranslationLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 37 additions & 6 deletions Loop/Window Management/WindowAction+Port.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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]

Expand All @@ -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 }
Expand All @@ -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."
)
)
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 81b52f8

Please sign in to comment.