diff --git a/sb-post-edit-block.php b/sb-post-edit-block.php index e68240e..a180566 100644 --- a/sb-post-edit-block.php +++ b/sb-post-edit-block.php @@ -21,14 +21,32 @@ * @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/writing-your-first-block-type/ */ function oik_sb_sb_post_edit_block_block_init() { + oik_sb_sb_post_edit_block_load_plugin_textdomain(); $args = [ 'render_callback' => 'oik_sb_sb_post_edit_block_dynamic_block']; $registered = register_block_type_from_metadata( __DIR__, $args ); + //bw_trace2( $registered, "registered" ); + /* + * Localise the script by loading the required strings for the build/index.js file + * from the locale specific .json file in the languages folder + */ + $ok = wp_set_script_translations( 'oik-sb-sb-post-edit-block-editor-script', 'sb-post-edit-block' , __DIR__ .'/languages' ); + //echo "?$ok?"; + + //add_filter( 'load_script_textdomain_relative_path', 'oik_load_script_textdomain_relative_path', 10, 2); + } function oik_sb_sb_post_edit_block_loaded() { add_action( 'init', 'oik_sb_sb_post_edit_block_block_init' ); } +function oik_sb_sb_post_edit_block_load_plugin_textdomain( $domain="sb-post-edit-block" ) { + $languages_dir = "$domain/languages"; + bw_trace2( $languages_dir, "languages dir" ); + $loaded = load_plugin_textdomain( $domain, false, $languages_dir ); + return $loaded; +} + /** * Implements the Post Edit block. *