Skip to content

feat: localize selection menu labels via selectionMenuLabels prop#415

Open
marcellov7 wants to merge 1 commit into
software-mansion:mainfrom
marcellov7:feat/localizable-selection-menu-labels
Open

feat: localize selection menu labels via selectionMenuLabels prop#415
marcellov7 wants to merge 1 commit into
software-mansion:mainfrom
marcellov7:feat/localizable-selection-menu-labels

Conversation

@marcellov7

Copy link
Copy Markdown

Summary

Closes #198.

The built-in copy actions (Copy, Copy as Markdown, Copy Image URL) are hardcoded in English in the native code. On non-English apps they stay in English while the OS-provided menu items (Look Up, Translate…) are localized, creating an inconsistent menu — exactly the problem reported in #198.

This adds a selectionMenuLabels prop on EnrichedMarkdownText so the labels can be overridden from JS (option 2 in the issue), typically wired to the app's i18n:

<EnrichedMarkdownText
  markdown={content}
  selectionMenuLabels={{
    copy: t('copy'),
    copyAsMarkdown: t('copyAsMarkdown'),
    copyImageUrl: t('copyImageUrl'),
    copyImageUrls: t('copyImageUrls'), // "{count}" is replaced by the image count
  }}
/>

Any label left undefined keeps its English default, so the change is fully backward compatible.

How it works

The labels are folded into the existing selectionMenuConfig codegen struct (normalized JS-side, where an empty string means "use the native default"), so no new native prop plumbing is introduced.

  • TS — new SelectionMenuLabels type + prop; normalization in native/EnrichedMarkdownText.tsx; struct fields added to both text/github codegen specs.
  • Android — labels read in MarkdownViewManagerUtils, applied in SelectionActionMode and threaded to the table and math copy menus.
  • iOS / macOS — labels carried on ENRMSelectionMenuConfig (strong owners on the view) and applied in EditMenuUtils(+macOS) and the TableContainerView / ENRMMathContainerView menus.

Scope

Covers EnrichedMarkdownText (commonmark + github flavor), including the table and math block copy menus listed in #198. EnrichedMarkdownTextInput keeps only its visibility config for now (the Format submenu labels could be a follow-up).

Notes for reviewers

  • Docs updated: docs/COPY_OPTIONS.md (new "Localizing Menu Labels" section) and docs/API_REFERENCE.md.
  • yarn typecheck and eslint pass locally. I couldn't run the native (Xcode/Gradle) builds or clang-format/ktlint in my environment, so please double-check the native formatting matches the hooks — happy to adjust.
  • No public API removed; existing behavior is unchanged when the prop is omitted.

🤖 Generated with Claude Code

The built-in copy actions (Copy, Copy as Markdown, Copy Image URL) were
hardcoded in English in the native code, so on non-English apps they did
not match the rest of the UI (the OS-provided items are localized, these
were not).

Add a `selectionMenuLabels` prop on `EnrichedMarkdownText` to override the
labels from JS — typically wired to the app's i18n. Any label left
undefined keeps its English default, so it is fully backward compatible.

- TS: new `SelectionMenuLabels` type + prop; labels folded into the
  existing `selectionMenuConfig` codegen struct and normalized JS-side
  (empty string = use native default).
- Android: labels read in `MarkdownViewManagerUtils`, applied in
  `SelectionActionMode` and threaded to the table and math copy menus.
- iOS/macOS: labels carried on `ENRMSelectionMenuConfig` and applied in
  `EditMenuUtils` (+macOS) and the table/math container menus.
- `copyImageUrls` is a `{count}` template for the multi-image case.
- Docs: COPY_OPTIONS.md and API_REFERENCE.md.

Scope: `EnrichedMarkdownText` (and github flavor). `EnrichedMarkdownTextInput`
keeps only the visibility config for now — can follow up.

Closes software-mansion#198

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context menu items are not localized

1 participant