Skip to content

Pass labels as props in RichEditor to make them translatable - #346

Open
SarahW91 wants to merge 3 commits into
inveniosoftware:masterfrom
ulbmuenster:richtexteditor_pass_labels_as_prop
Open

SarahW91 wants to merge 3 commits into
inveniosoftware:masterfrom
ulbmuenster:richtexteditor_pass_labels_as_prop

Conversation

@SarahW91

@SarahW91 SarahW91 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Description

Problem: RichEditor hardcodes several user-facing strings ("Attach files", "Uploading file...", "Preview math equations", image alt text). Since this package has no translation workflow of its own, consuming packages cannot translate these strings, leading to non-translatable UI elements (e.g. the "Attach files" button in invenio-requests' comment editor).

This PR introduces an optional labels prop (object) with sensible English defaults, matching current behavior. Consuming packages can override any subset of labels with translated strings without needing to fork or patch the component. Fully backwards-compatible — no labels prop means unchanged behavior.

Disclaimer: I used Claude to help me with this PR since I'm not a React/JS specialist.

I tested this code locally and it works and allows to the mentioned labels to be translated, if props are passed by invenio-requests. I'll create a separate PR there for passing the translatable strings.

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

@SarahW91

SarahW91 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

PR in invenio-requests: inveniosoftware/invenio-requests#644

@mkloeppe mkloeppe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Default labels are used when no additional labels are provided through props.

Comment thread src/lib/forms/RichEditor.js Outdated
* only need to override the strings they actually want to translate.
*/
getLabels = () => {
return { ...defaultLabels, ...this.props.labels };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return { ...defaultLabels, ...this.props.labels };
const { labels } = this.props;
return { ...defaultLabels, ...labels };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to please the linter. Destructuring props before using them is the way.

@Samk13 Samk13 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!
the labels are wired into the existing:
attachment button
upload message
preview tooltip/title
Should we also forward labels through RichInputField? It currently constructs RichEditor without passing that prop.

Have you tested changing languages after mounting is working? TinyMCE ignores initialization configuration changes after launch, and the toolbar labels are captured during setup.

Screenshots are always welcome showing the translated attachment button, upload message, and preview tooltip/dialog, plus an example confirming that omitted labels retain their English defaults. Thanks!

@SarahW91

SarahW91 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Good points, I'll adjust RichInputField as well!

As for the screenshots:

"Attach files" does get translated:
image

No translation for "preview math equations" was found, so the default is used:
image

Wasn't quick enough with a screenshot for the upload message ;) Couldn't find the image description message in the UI.

Switching back and forth between languages didn't seem to be a problem, neither for the button nor the toolbar labels.

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.

3 participants