-
-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LocalizedStringKey initializer to Recorder to support localizing the title #161
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e07095a
Added another KeyboardShortcuts.Recorder.init that takes LocalizedStr…
rtharston cd49359
Added text to the previews to show the new initializer working
rtharston 9e6300d
Switch back to String
rtharston 926089a
Update Recorder.swift
sindresorhus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -151,18 +174,18 @@ extension KeyboardShortcuts.Recorder { | |
|
||
@available(macOS 10.15, *) | ||
#Preview { | ||
KeyboardShortcuts.Recorder(for: .init("xcodePreview")) | ||
KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used the key of an existing string so the preview wouldn't require a new string to be localized. |
||
.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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
@_disfavoredOverload
can't be used in this package, this line can be changed to something like:key title: LocalizedStringKey
to remove the conflict between this init and the init that accepts StringProtocol.