Skip to content

Make the default texts of field controls translatable - #110

Merged
dnnsjsk merged 1 commit into
inline0:7.7.2from
Contributolo:fix/translatable-editor-defaults
Oct 15, 2026
Merged

dnnsjsk merged 1 commit into
inline0:7.7.2from
Contributolo:fix/translatable-editor-defaults

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

Follow-up to #100.

Some default texts of the field controls are assembled at runtime, so no translation tool can extract them and they stay in English even when a translation exists:

Field Default text Before
files Open Media Library __( item?.textMediaButton || 'Open Media Library', … )
link Select Link __( item?.textButton || 'Select Link', … )
repeater Add row, Do you want to delete this row? same pattern
select Reset to default __( item?.allowReset || 'Reset to default' )
wysiwyg Align left, center, right, justify __( `Align ${align}` )
wysiwyg Switch to Visual, Switch to Code __( `Switch to ${codeMode ? 'Visual' : 'Code'}` )

Each variant is now a literal string. Custom texts from block.json (textMediaButton, textButton, textRemove) still go through __( text, true ) as before, so blocks that set them are unchanged.

Two small fixes come with it:

  • The reset button of select fields had no text. allowReset is a boolean, so __( allowReset || 'Reset to default' ) received true and @wordpress/i18n returned it unchanged, which React does not render. It now shows "Reset to default".
  • textRemove: true opened a confirm dialog with the text "true". It now asks the default question. textRemove: false and string values behave as before.

Otherwise the English output is the same. I did not commit rebuilt bundles: a local build of unchanged main already differs from the committed assets on my machine, so please rebuild them as with #100.

npm run check passes.

The default texts of textMediaButton, textButton (link and repeater),
textRemove, the reset button of select fields, the alignment buttons and
the code toggle of the WYSIWYG field were assembled at runtime, for
example __( value || 'Add row' ) or __( `Align ${align}` ). No
translation tool can extract such strings, so they stayed in English in
every language. Each variant is now a literal string. Custom texts from
block.json still go through __() in the default text domain as before.

The reset button of select fields had no label: allowReset is a boolean,
so __( allowReset || 'Reset to default' ) returned true, which React does
not render.
@dnnsjsk
dnnsjsk changed the base branch from main to 7.7.2 October 15, 2026 11:07
@dnnsjsk
dnnsjsk merged commit 284ba10 into inline0:7.7.2 Oct 15, 2026
dnnsjsk added a commit that referenced this pull request Oct 15, 2026
Integrate #110, #111, #112, #113, and #114 into 7.7.2 with rebuilt bundles, docs, and regression coverage. Preserve custom reset labels and row preferences; validate plural translations and locale switching.

Fixes #115. Fixes #95.
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.

2 participants