Here is my code.
I based it on CapitaineWP formation and template.
I have the .pot, .po, .mo and .json files.
$script_asset_path = PERSO_FOLDER.”/build/index.asset.php”;
if ( ! file_exists( $script_asset_path ) ) {
throw new Error(
‘You need to run npm start or npm run build for the “create-block/perso-chacha-bases” block first. (‘.$script_asset_path.’)’
);
}
$index_js = '/build/index.js';
$script_asset = require( $script_asset_path );
wp_register_script(
'perso-chacha-bases-block-editor',
PERSO_URL.$index_js,
$script_asset['dependencies'],
$script_asset['version']
);
wp_set_script_translations(
'perso-chacha-bases-block-editor',
'perso-chacha',
PERSO_FOLDER . '/languages'
);
$editor_css = '/build/index.css';
wp_register_style(
'perso-chacha-bases-block-editor',
PERSO_URL.$editor_css,
array(),
filemtime( PERSO_FOLDER.$editor_css )
);
$style_css = '/build/style-index.css';
wp_register_style(
'perso-chacha-bases-block',
PERSO_URL.$style_css,
array(),
filemtime( PERSO_FOLDER.$style_css )
);
register_block_type( 'create-block/perso-chacha-bases', array(
'editor_script' => 'perso-chacha-bases-block-editor',
'editor_style' => 'perso-chacha-bases-block-editor',
'style' => 'perso-chacha-bases-block',
) );
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I found the problem.
I needed to add -perso-chacha-bases-block-editor after fr_FR in the json filename.
I found out this solution here: Gutenberg translation is not working
Big thank you!
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0