Skip to content

Register script translations and translate remaining editor strings - #100

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:i18n-editor-strings
Oct 14, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:i18n-editor-strings

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

Problem

On a site with a non-English locale the editor UI stays English, even when a language pack for the blockstudio text domain is installed:

  • The file field card shows the raw attachment type as a badge (IMAGE).
  • More, Open in popup and the attribute Value placeholder are not translatable.
  • All other __() strings in the editor stay English as well.

Cause

  • includes/classes/blocks.php (enqueue_editor_assets(), the blockstudio-blocks script) and includes/classes/admin-page.php (the blockstudio-admin-page script) enqueue bundles that depend on wp-i18n and call __( ..., 'blockstudio' ) through src/utils/__.ts. Neither handle is passed to wp_set_script_translations(), so WordPress never prints translation data for them. Per the Block Editor Handbook, Internationalization, that call is the last required step to make JavaScript translatable.
  • src/blocks/components/list/cards.tsx: the badge renders dataObject.media_type (the REST value image/file) and CSS upper-cases it, so it is not a translatable string at all.
  • src/blocks/components/fields/components/attributes.tsx (label="More", placeholder="Value") and src/blocks/components/fields/components/code.tsx (label: 'Open in popup') are not wrapped in __().

Solution

  • Call wp_set_script_translations( <handle>, 'blockstudio' ) for both handles.
  • Wrap the three hard-coded strings in __() and map the media type badge to __( 'Image' ) / __( 'File' ) (unknown values are still shown as is).
  • Rebuild includes/admin/assets/blocks/index.tsx.js.

No translation files are added. This only makes the strings translatable, for example via a language pack or a translation plugin that writes to wp-content/languages/plugins/.

Test

  • composer cs, npm run lint, tsc --noEmit pass; npm run build output is committed.
  • The E2E suite needs Docker (wp-env), which I could not run locally; CI will cover it. Existing E2E selectors do not match on the changed texts.

The editor and admin-page scripts load wp-i18n and call __() with the
blockstudio text domain, but neither handle is passed to
wp_set_script_translations(), so WordPress never prints translation data
for them and every string stays English regardless of the site locale.

Register both handles, and wrap the strings that were still hard-coded:
the "More" menu label, the attribute value placeholder, the "Open in
popup" action and the media type badge on file cards, which printed the
raw REST media_type value ("image").
@dnnsjsk

dnnsjsk commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Merged into the 7.7.0 release branch in c0609b8. Rebuilt the editor bundle from the combined 7.7.0 sources to retain the recent editor/cache fixes, and added three WordPress unit tests plus four browser tests for translation loading, attribute controls, popup actions, and translated media badges with unknown-type fallback. Documentation and changelog are updated.

All new tests and the existing editor regression tests passed. The combined branch at 0398eaf passed all 14 CI jobs and all 5 distribution checks: https://github.com/inline0/blockstudio/actions/runs/38565550557 and https://github.com/inline0/blockstudio/actions/runs/38565550479.

Leaving this PR open against main until the release branch is merged, so GitHub records the original contribution as merged.

@dnnsjsk
dnnsjsk merged commit c0609b8 into inline0:main Oct 14, 2026
@dnnsjsk

dnnsjsk commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Included in Blockstudio 7.7.0. The full CI suite passed. Thanks for the contribution.

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