Repository navigation
Ship translations with the plugin, starting with German - #111
Merged
Merged
Conversation
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.
Blockstudio is not on WordPress.org, so WordPress never downloads a language pack for it, and the strings made translatable in 7.7.0 stayed in English. Translations can now ship in the languages folder. - Translations::load() loads the PHP translations on init and after a locale switch, from wp-content/languages/plugins first, then from the bundled folder. This works for plugin, must-use plugin and Composer installs, because the path comes from BLOCKSTUDIO_DIR. - Both script bundles pass a translation path to wp_set_script_translations(). WordPress loads the handle-named JSON file from there, which does not depend on the install location. - npm run i18n extracts the strings from PHP and from the TypeScript sources, including the @/utils/__ wrapper, updates languages/blockstudio.pot and every .po file, and writes the .mo, .l10n.php and per-handle .json files. - npm run i18n:check is part of npm run check. It fails when a string is assembled at runtime or the translation files are out of date. - A new docs page explains how to use, override and contribute translations.
de_DE and de_DE_formal, so sites in the formal locale get the same translation with "Sie" instead of "du" where the text addresses the reader.
The canvas menu (Pages, Blocks, Fit to view, Zoom to 100%, Live mode, Canvas options, Close focus mode) and the copy feedback of the devtools overlay were plain English text. They now go through __(), both scripts load their translations like the editor bundles, and the German files cover them. The placeholder check of npm run i18n now applies to every string with a placeholder, not only to PHP strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #110: the first commit here is that PR, so please merge it first.
Since #100 the editor strings are translatable, but no translation reaches anyone: Blockstudio is not on WordPress.org, so WordPress never downloads a language pack for the
blockstudiotext domain. This PR ships translations with the plugin, adds German, and gives everyone a simple way to add or fix a language.Runtime
Translationsclass.Translations::load()runs oninitandchange_localeand loadswp-content/languages/plugins/blockstudio-{locale}.mofirst, then the bundled file. For a string in both, WordPress uses the file loaded first, so a site can still override single strings.load_textdomain()also picks up the.l10n.phpfile (WordPress 6.5+).blockstudio-blocks,blockstudio-admin-page,blockstudio-canvasandblockstudio-devtoolsnow pass a path towp_set_script_translations(). With a path,load_script_textdomain()first looks for{domain}-{locale}-{handle}.jsonin it, which does not depend on where Blockstudio is installed. A matching file inwp-content/languages/pluginstakes precedence here as well (Translations::script_path()).BLOCKSTUDIO_DIR, so plugin, must-use plugin and Composer installs work the same.Tooling
npm run i18nrunsscripts/i18n.ts(no new dependencies). Itblockstudiodomain, translator comments,php-format) and from the TypeScript sources of each script bundle (@/utils/__and@wordpress/i18n), following the imports from the webpack entries,languages/blockstudio.potand updates every.pofile,.pointo.mo,.l10n.phpand one.jsonper script handle.wp i18n make-potdoes not fit here: it parses only.jsand.jsx, and the@/utils/__wrapper hides the text domain. The generated.mofiles are byte-identical tomsgfmt --no-hash. The.l10n.phpand.jsonfiles have the structure ofWP_Translation_File_PHP::export()and WP-CLImake-json.npm run i18n:checkis added tonpm run check. It fails when a string is assembled at runtime, when a translation drops a placeholder, or whenlanguages/is out of date. A.pofile reformatted by an editor such as Poedit still passes, it only has to contain the same strings. The POT references have no line numbers, so unrelated code changes do not make it stale. If you prefer to keep it out ofcheck, removing it there is enough.German
de_DEandde_DE_formal, all 127 strings. The formal file differs where a text addresses the reader. I am happy to maintain the German translation.Docs
New page
general/translations(using, overriding and contributing translations), docs count raised to 73, LLM index rebuilt withnpm run build:llm, one row in the CLAUDE.md command table. The new class says@since 7.8.0, please adjust to the release it lands in.Tests
tests/unit/i18n/BundledTranslationsTest.php: PHP strings inde_DEandde_DE_formal, English for an unknown locale, the editor bundle printing the bundled JSON, compiled files present for every.po.npm run check,composer cs, PHPStan, and a WordPress Playground site (WordPress latest, PHP 8.4, site language German) with this branch mounted as the plugin and the bundles rebuilt locally. The editor shows "Zeile hinzufügen", "Mediathek öffnen" and "Link auswählen", the Tools page loads its German JSON, PHP messages are German,de_DE_formalloads its own file, an unknown locale stays English, and files inwp-content/languages/pluginswin for PHP and JS.The last commit also makes the canvas menu (Pages, Blocks, Fit to view, Zoom to 100%, Live mode, Canvas options, Close focus mode) and the copy feedback of the devtools overlay translatable. A search over
src/(JSX text, label and title attributes, notices) finds no other visible English text outside__(). The pages bundle has no visible text.