Skip to content

Commit

Permalink
Enable localization of blocks #47
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Aug 31, 2021
1 parent 7d09386 commit 846927a
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions oik-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ function oik_blocks_register_dynamic_blocks() {
* from the locale specific .json file in the languages folder.
*/
$ok = wp_set_script_translations( 'oik-block-blockicon-editor-script', 'oik-blocks' , __DIR__ .'/languages' );
bw_trace2( $ok, "OK?");
//bw_trace2( $ok, "OK?");
add_filter( 'load_script_textdomain_relative_path', 'oik_blocks_load_script_textdomain_relative_path', 10, 2);
}

/**
Expand All @@ -303,13 +304,32 @@ function oik_blocks_block_type_metadata( $metadata ) {
$textdomain = $name_parts[0];
if ( 'oik-block' === $textdomain ) {
$textdomain = 'oik-blocks';
$metadata['textdomain'] = $textdomain;
}
$metadata['textdomain'] = $textdomain;

}
return $metadata;
}


/**
* Filters $relative so that md5's match what's expected.
*
* Depending on how it was built the `build/index.js` may be preceded by `./` or `src/block-name/../../`.
* In either of these situations we want the $relative value to be returned as `build/index.js`.
* This then produces the correct md5 value and the .json file is found.
*
* @param $relative
* @param $src
*
* @return mixed
*/
function oik_blocks_load_script_textdomain_relative_path( $relative, $src ) {
if ( false !== strrpos( $relative, './build/index.js' )) {
$relative = 'build/index.js';
}
//bw_trace2( $relative, "relative");
return $relative;
}

function oik_blocks_register_block_patterns() {
if ( false ) {
Expand Down

0 comments on commit 846927a

Please sign in to comment.