Skip to content

Commit

Permalink
Localize editor and setting scripts separately.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndiego committed Feb 13, 2023
1 parent 87cefac commit 1a52801
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions includes/class-block-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ private function __construct() {
*/
public function actions() {
add_action( 'init', array( $this, 'load_textdomain' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'block_localization' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'editor_scripts_localization' ) );

// Use admin_enqueue_scripts here, otherwise the settings page will not be translated.
add_action( 'admin_enqueue_scripts', array( $this, 'setting_scripts_localization' ) );

// Specific fixes/work arounds for server-side blocks.
add_action( 'wp_loaded', array( $this, 'add_attributes_to_registered_blocks' ), 999 );
Expand Down Expand Up @@ -205,18 +208,27 @@ public function load_textdomain() {
}

/**
* Enqueue localization data for our blocks.
* Enqueue localization data for editor scripts.
*
* @since 1.0.0
*/
public function block_localization() {
public function editor_scripts_localization() {
if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations(
'block-visibility-editor-scripts',
'block-visibility',
BLOCK_VISIBILITY_ABSPATH . '/languages'
);
}
}

/**
* Enqueue localization data for setting page scripts.
*
* @since 2.6.0
*/
public function setting_scripts_localization() {
if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations(
'block-visibility-setting-scripts',
'block-visibility',
Expand Down

0 comments on commit 1a52801

Please sign in to comment.