-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Hey there,
I guess I've found an issue regarding the translation of block.json content. I'm not quite sure where the exact problem is: WP-CLI or the Gutenberg project?
Summary:
After generating PO- and JSON-Files with the according CLI-commands Gutenberg does not translate strings from block.json.
Steps to reproduce:
-
Install a Test block
cd /wp-content/plugins
npx @wordpress/create-block my-test-block -
Edit /src/index.js to use block-meta:
import metadata from './block.json';
registerBlockType(metadata, {
edit: Edit,
save,
});
- Fix
editorScriptpath in block.json (otherwise MD5-hashes are not correct)
{
"editorScript": "file:index.js",
...
}
-
Create POT
cd /my-test-block
wp i18n make-pot . languages/my-test-block.pot --skip-php --exclude=build,node_modules -
Create PO-File and translate (at least the strings from the block.json)
-
Create JSON-File:
cd languages
wp i18n make-json my-test-block-de_DE.po ./ --no-purge '--use-map={ "src/index.js": "build/index.js", "src/save.js": "build/index.js", "src/edit.js": "build/index.js", "src/block.json": "build/index.js" }' -
Run build
cd wp-content/plugins/my-test-block
npm run build -
Fix path in my-test.block.php
add_filter(
'load_script_translation_file',
function ( string $file, string $handle, string $domain ) {
if ( 'my-test-block' !== $domain ) {
return (string) $file;
}
return plugin_dir_path( __FILE__ ) . 'languages/' . basename( $file );
},
10,
3
);
- Activate plugin and add the block into a post. Set language accordingly.
The title is not translated.
Environment
wp cli info
OS: Darwin 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101 arm64
Shell: /bin/zsh
PHP binary: /opt/homebrew/Cellar/php@7.4/7.4.28.reinstall/bin/php
PHP version: 7.4.28
php.ini used: /opt/homebrew/etc/php/7.4/php.ini
MySQL binary:
MySQL version:
SQL modes:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /Users/fs/Local Sites/meinwp/app/public/wp-content/plugins/my-test-block/languages
WP-CLI packages dir:
WP-CLI global config: /Users/fs/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.6.0
Expected Result
I would expect that the block title and the description gets translated.
Actual Results
Title and description gets not translated.
Any help is much appreciated.