-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
Changes from 2 commits
e07095a
cd49359
9e6300d
926089a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,7 +114,7 @@ | |
- 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: String, | ||
_ title: LocalizedStringKey, | ||
name: KeyboardShortcuts.Name, | ||
onChange: ((KeyboardShortcuts.Shortcut?) -> Void)? = nil | ||
) { | ||
|
@@ -128,6 +128,29 @@ | |
} | ||
} | ||
|
||
@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 | ||
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. See the description for an explanation of |
||
public init<S>( | ||
_ title: S, | ||
rtharston marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name: KeyboardShortcuts.Name, | ||
onChange: ((KeyboardShortcuts.Shortcut?) -> Void)? = nil | ||
) where S : StringProtocol { | ||
self.init( | ||
for: name, | ||
onChange: onChange, | ||
hasLabel: true | ||
) { | ||
Text(title) | ||
} | ||
} | ||
} | ||
|
||
@available(macOS 10.15, *) | ||
extension KeyboardShortcuts.Recorder { | ||
/** | ||
|
@@ -151,18 +174,18 @@ | |
|
||
@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 |
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.