Friday, June 17, 2022
HomeWordPress Developmentplugins - add Internationalization in WordPress utilizing Javascript/React?

plugins – add Internationalization in WordPress utilizing Javascript/React?


I’m making an attempt to comply with this text https://developer.wordpress.org/block-editor/how-to-guides/internationalization/ as a way to translate my block.

I created my block utilizing https://developer.wordpress.org/block-editor/getting-started/create-block/ script.

Then in my gutenpride.php, I added this code.

perform myguten_set_script_translations()
{
    wp_register_script('myguten-script', plugins_url('/temp.js', __FILE__), ['wp-blocks', 'wp-i18n', 'wp-element'], filemtime(__DIR__ . '/temp.js'));

    wp_set_script_translations('myguten-script', 'myguten', plugin_dir_path(__FILE__) . 'languages');

    wp_localize_script('myguten-script', 'myguten', [
        'plugin_url' => plugins_url("https://wordpress.stackexchange.com/", __FILE__),
    ]);

    wp_enqueue_script('myguten-script');
}
add_action('init', 'myguten_set_script_translations');

As you’ll be able to see, I’m registering a temp.js file and giving it all of the required dependencies.

The temp.js file works and is operating.

As instructed by the interpretation article I added two recordsdata in my language folder

1. myguten-co.po
2. myguten.pot

Then I created the JSON file for myguten-co.po and altered the location language to Esperanto.

However after I see the block or add the brand new block but I don’t get the translated label.

Is there something I’m lacking?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments