-
Notifications
You must be signed in to change notification settings - Fork 55
feat: localize selection menu labels via selectionMenuLabels prop #415
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
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. Looks like this has the same issues as the kotlin. The props are not being walked down to children on updateProps: follow the existing iOS prop-update idiom - see |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,11 @@ | |
|
|
||
| #if TARGET_OS_OSX | ||
|
|
||
| static NSString *resolveMenuLabel(NSString *_Nullable label, NSString *fallback) | ||
| { | ||
| return label.length > 0 ? label : fallback; | ||
| } | ||
|
|
||
|
Comment on lines
+10
to
+14
Collaborator
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. Nitpick: On macOS, the table and math context menus fall back to |
||
| NSMenu *_Nullable buildEditMenuForSelection(NSAttributedString *attributedText, NSRange range, | ||
| NSString *_Nullable cachedMarkdown, StyleConfig *styleConfig, | ||
| NSArray *suggestedActions, NSArray<NSMenuItem *> *_Nullable customItems, | ||
|
|
@@ -25,8 +30,9 @@ | |
|
|
||
| // Replace the system Copy item with our enhanced version (copies RTF/HTML/Markdown). | ||
| // This mirrors the iOS behaviour where we replace the standard-edit Copy action. | ||
| NSString *copyTitle = resolveMenuLabel(selectionMenuConfig.copyLabel, @"Copy"); | ||
| NSMenuItem *enhancedCopy = | ||
| ENRMCreateMenuItem(@"Copy", ^{ copyAttributedStringToPasteboard(selectedText, markdown, styleConfig); }); | ||
| ENRMCreateMenuItem(copyTitle, ^{ copyAttributedStringToPasteboard(selectedText, markdown, styleConfig); }); | ||
| NSInteger systemCopyIndex = [menu indexOfItemWithTarget:nil andAction:@selector(copy:)]; | ||
| if (systemCopyIndex != NSNotFound) { | ||
| [menu removeItemAtIndex:systemCopyIndex]; | ||
|
|
@@ -39,13 +45,21 @@ | |
| } | ||
|
|
||
| if (selectionMenuConfig.copyAsMarkdown && markdown.length > 0) { | ||
| [menu addItem:ENRMCreateMenuItem(@"Copy as Markdown", ^{ copyStringToPasteboard(markdown); })]; | ||
| NSString *copyMarkdownTitle = resolveMenuLabel(selectionMenuConfig.copyAsMarkdownLabel, @"Copy as Markdown"); | ||
| [menu addItem:ENRMCreateMenuItem(copyMarkdownTitle, ^{ copyStringToPasteboard(markdown); })]; | ||
| } | ||
|
|
||
| if (selectionMenuConfig.copyImageURL && imageURLs.count > 0) { | ||
| NSString *title = (imageURLs.count == 1) | ||
| ? @"Copy Image URL" | ||
| : [NSString stringWithFormat:@"Copy %lu Image URLs", (unsigned long)imageURLs.count]; | ||
| NSString *title; | ||
| if (imageURLs.count == 1) { | ||
| title = resolveMenuLabel(selectionMenuConfig.copyImageUrlLabel, @"Copy Image URL"); | ||
| } else if (selectionMenuConfig.copyImageUrlsLabel.length > 0) { | ||
| NSString *countString = [@(imageURLs.count) stringValue]; | ||
| title = [selectionMenuConfig.copyImageUrlsLabel stringByReplacingOccurrencesOfString:@"{count}" | ||
| withString:countString]; | ||
| } else { | ||
| title = [NSString stringWithFormat:@"Copy %lu Image URLs", (unsigned long)imageURLs.count]; | ||
|
Collaborator
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. Same issue as the comment above in this file |
||
| } | ||
| [menu addItem:ENRMCreateMenuItem(title, ^{ | ||
| NSString *urlsToCopy = [imageURLs componentsJoinedByString:@"\n"]; | ||
| copyStringToPasteboard(urlsToCopy); | ||
|
|
||
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.
Looks like this code is missing a assign in the prop change section. We need to update everything in case of re-update
For example if someone updates a prop (customer changes language on page without a remount), they would get wrong language
Look at
EnrichedMarkdown.kt 229-235for an example