Gutenberg block localization does not work
-
Good day.
Learning how to make widgets for Gutenberg. I generated the base of the plugin according to the article https://developer.www.ads-software.com/block-editor/ , the icon was added normally, the widget is added to the block, there are no problems.
The Edit and Save functions have so far been left by default, what the generator inserted:
export default function Edit() { return ( <p { ...useBlockProps() }> { __( 'Postslider – hello from the editor new!', 'postslider' ) } </p> ); } export default function save() { return ( <p { ...useBlockProps.save() }> { __( 'Postslider – hello from the saved content!', 'postslider' ) } </p> ); }
As you can see, __() is called, that is, the text must be localized. I generated a pot file (the lines were added there normally), made a po file for the ru_RU locale and compiled it into mo using PoEdit.
I load the textdomain in the plugin:
add_action( 'init', 'postslider_load_textdomain' ); function postslider_load_textdomain() { $dirname = dirname( plugin_basename( __FILE__ ) ) . '/languages'; $loaded = load_plugin_textdomain( 'postslider', false, $dirname ); if ($loaded) { echo '<script>console.log("ok");</script>'; } else { echo '<script>console.log("not ok");</script>'; } }
The MO file is loading correctly, I checked – $loaded is set to true.
It seems like I did everything according to Feng Shui, but the translation does not occur, even when the site language is set to Ru, English text is shown.
Tell me, please, what else can be done to make the translation appear?
Thank you in advance,
Serge.
- The topic ‘Gutenberg block localization does not work’ is closed to new replies.