Repository navigation
Register script translations and translate remaining editor strings - #100
Conversation
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").
|
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. |
|
Included in Blockstudio 7.7.0. The full CI suite passed. Thanks for the contribution. |
Problem
On a site with a non-English locale the editor UI stays English, even when a language pack for the
blockstudiotext domain is installed:IMAGE).More,Open in popupand the attributeValueplaceholder are not translatable.__()strings in the editor stay English as well.Cause
includes/classes/blocks.php(enqueue_editor_assets(), theblockstudio-blocksscript) andincludes/classes/admin-page.php(theblockstudio-admin-pagescript) enqueue bundles that depend onwp-i18nand call__( ..., 'blockstudio' )throughsrc/utils/__.ts. Neither handle is passed towp_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 rendersdataObject.media_type(the REST valueimage/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") andsrc/blocks/components/fields/components/code.tsx(label: 'Open in popup') are not wrapped in__().Solution
wp_set_script_translations( <handle>, 'blockstudio' )for both handles.__()and map the media type badge to__( 'Image' )/__( 'File' )(unknown values are still shown as is).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 --noEmitpass;npm run buildoutput is committed.