php – Custom plugin translation not working

Question

I made a plugin that contains 2 custom gutenberg blocks created with react and jQuery (for some front-end stuff) and I’m having troubles translating them. There are no translation strings inside the PHP files. Basically there are no PHP files, except for the main plugin file, the settings and another file where I’m doing enqueue of Google Places and Google ReCapcha. Inside my main PHP file I have specified in the top section my text domain, then I have 2 functions:

function gutenberg_blocks_init(){
    register_block_type(
        __DIR__ . '/build/block-a/',
    );
    register_block_type(
        __DIR__ . '/build/block-b/',
    );
}
add_action('init', 'gutenberg_blocks_init')

and

function load_translations() {
    load_plugin_textdomain('myblocks', false, dirname(plugin_basename(__FILE__)) . '/languages/');
}
add_action( 'plugins_loaded', 'load_translations' )

Inside my index.js and inside my jQuery front-end file I’m doing import { __ } from 'wordpress user/i18n' and all the strings are written as it should – __( 'String to translate', 'myblocks' ). I generated a POT file using WP-CLI and from there I translated all the strings using PoEdit and created PO and MO files. The POT file successfully got all the strings from the js files. Yet the translations are not working.. Tried instead of all this to use Loco Translate, but it’s not working again.. Is there anything that I’m missing? How can I translate my blocks? Tried a bunch of different ways and none of them worked so far.. Tried with json files and wp_set_script_translations, but didn’t quite understand what to do and it didn’t worked..

0
tsvetko.krastev 3 months 2023-12-08T14:49:31-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse