Skip to content

Commit

Permalink
Add LocalizedStringKey initializer to Recorder to support localiz…
Browse files Browse the repository at this point in the history
…ing the title (#161)

Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
rtharston and sindresorhus authored Jan 14, 2024
1 parent c252200 commit 8964a7d
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions Sources/KeyboardShortcuts/Recorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ extension KeyboardShortcuts.Recorder<Text> {
- Parameter name: Strongly-typed keyboard shortcut name.
- Parameter onChange: Callback which will be called when the keyboard shortcut is changed/removed by the user. This can be useful when you need more control. For example, when migrating from a different keyboard shortcut solution and you need to store the keyboard shortcut somewhere yourself instead of relying on the built-in storage. However, it's strongly recommended to just rely on the built-in storage when possible.
*/
public init(
_ title: LocalizedStringKey,
name: KeyboardShortcuts.Name,
onChange: ((KeyboardShortcuts.Shortcut?) -> Void)? = nil
) {
self.init(
for: name,
onChange: onChange,
hasLabel: true
) {
Text(title)
}
}
}

@available(macOS 10.15, *)
extension KeyboardShortcuts.Recorder<Text> {
/**
- Parameter title: The title of the keyboard shortcut recorder, describing its purpose.
- Parameter name: Strongly-typed keyboard shortcut name.
- Parameter onChange: Callback which will be called when the keyboard shortcut is changed/removed by the user. This can be useful when you need more control. For example, when migrating from a different keyboard shortcut solution and you need to store the keyboard shortcut somewhere yourself instead of relying on the built-in storage. However, it's strongly recommended to just rely on the built-in storage when possible.
*/
@_disfavoredOverload
public init(
_ title: String,
name: KeyboardShortcuts.Name,
Expand Down Expand Up @@ -151,18 +174,18 @@ extension KeyboardShortcuts.Recorder {

@available(macOS 10.15, *)
#Preview {
KeyboardShortcuts.Recorder(for: .init("xcodePreview"))
KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview"))
.environment(\.locale, .init(identifier: "en"))
}

@available(macOS 10.15, *)
#Preview {
KeyboardShortcuts.Recorder(for: .init("xcodePreview"))
KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview"))
.environment(\.locale, .init(identifier: "zh-Hans"))
}
@available(macOS 10.15, *)
#Preview {
KeyboardShortcuts.Recorder(for: .init("xcodePreview"))
KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview"))
.environment(\.locale, .init(identifier: "ru"))
}
#endif

0 comments on commit 8964a7d

Please sign in to comment.