Skip to content

Commit

Permalink
Merge branch 'press11-171' of github.com:newfold-labs/wp-module-patte…
Browse files Browse the repository at this point in the history
…rns into press11-171
  • Loading branch information
mr-vara committed Feb 25, 2025
2 parents a268681 + f41c6ed commit a91f4e4
Show file tree
Hide file tree
Showing 10 changed files with 1,280 additions and 1,260 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"i18n-po": "vendor/bin/wp i18n update-po ./languages/nfd-wonder-blocks.pot ./languages",
"i18n-mo": "vendor/bin/wp i18n make-mo ./languages",
"i18n-php": "vendor/bin/wp i18n make-php ./languages",
"i18n-json": "rm -f languages/*.json && vendor/bin/wp i18n make-json ./languages --no-purge --pretty-print",
"i18n-json": "find ./languages -name \"*.json\" -exec rm {} \\; && vendor/bin/wp i18n make-json ./languages --no-purge --pretty-print",
"i18n": [
"@i18n-pot",
"@i18n-po",
Expand Down
32 changes: 26 additions & 6 deletions includes/Library/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function __construct() {

\add_action( 'init', array( PluginService::class, 'setup' ) );
\add_action( 'init', array( __CLASS__, 'load_text_domain' ), 100 );

\add_filter( 'load_script_translation_file', array( __CLASS__, 'load_script_translation_file' ), 10, 3 );
}

/**
Expand Down Expand Up @@ -76,15 +78,34 @@ public static function register_assets() {
)
);

\wp_set_script_translations(
'nfd-wonder-blocks',
'nfd-wonder-blocks',
NFD_WONDER_BLOCKS_DIR . '/languages'
);

\wp_enqueue_script( 'nfd-wonder-blocks' );
\wp_enqueue_style( 'nfd-wonder-blocks' );
}
}

\wp_set_script_translations(
'nfd-wonder-blocks',
'nfd-wonder-blocks',
NFD_WONDER_BLOCKS_DIR . '/languages'
);
/**
* Filter default WP script translations file to load the correct one
*
* @param string $file The translations file.
* @param string $handle Script handle.
* @param string $domain The strings textdomain.
* @return string
*/
public static function load_script_translation_file( $file, $handle, $domain ) {

if ( 'nfd-wonder-blocks' === $handle ) {
$locale = determine_locale();
$key = md5( 'build/' . NFD_WONDER_BLOCKS_VERSION . '/wonder-blocks.js' );
$file = NFD_WONDER_BLOCKS_DIR . "/languages/{$domain}-{$locale}-{$key}.json";
}

return $file;
}

/**
Expand Down Expand Up @@ -181,5 +202,4 @@ public static function load_text_domain() {
NFD_WONDER_BLOCKS_DIR . '/languages'
);
}

}
Loading

0 comments on commit a91f4e4

Please sign in to comment.