Skip to content

Commit

Permalink
Merge pull request #2316 from vektor-inc/fix/adjust-translation-loadi…
Browse files Browse the repository at this point in the history
…ng-for-wp-6.7-2

[ WP6.7 ] 日本語の翻訳が効いていなかったのを修正しました(リフレッシュ) #2311
  • Loading branch information
mtdkei authored Nov 13, 2024
2 parents 39f506c + 3c1b54e commit 6077c45
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
24 changes: 21 additions & 3 deletions inc/vk-blocks/vk-blocks-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,30 @@ function vk_blocks_active() {
return true;
}

// 翻訳を実行
add_action(
'plugins_loaded',
function () {
// Load language files.
$path = dirname( plugin_basename( __FILE__ ) ) . '/languages';
load_plugin_textdomain( 'vk-blocks-pro', false, $path );
// サイトのロケールを取得
$locale = determine_locale();
// 翻訳ファイルのパスを指定
$path = plugin_dir_path( __FILE__ ) . 'languages';

// 日本語の設定のみ翻訳ファイルを読み込み
if ( strpos( $locale, 'ja' ) === 0 ) {
// PHPファイルの翻訳読み込み
load_textdomain( 'vk-blocks-pro', $path . '/vk-blocks-pro-ja.mo' );

// JavaScriptファイルの翻訳設定
add_action(
'wp_enqueue_scripts',
function () use ( $path ) {
// スクリプト登録後に翻訳設定
wp_set_script_translations( 'vk-blocks-build-js', 'vk-blocks-pro', $path );
wp_set_script_translations( 'vk-blocks-admin-js', 'vk-blocks-pro', $path );
}
);
}
}
);

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ e.g.

== Changelog ==

[ Specification change ] Adjusted translation file loading to comply with changes in WordPress 6.7.
[ Bug fix ][ Table of Contents (Pro) ] Fixed "CLOSE" label not appearing after clicking the "OPEN" button when the initial state is set to "CLOSE".

= 1.90.1 =
Expand Down
23 changes: 20 additions & 3 deletions vk-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,26 @@ function vk_blocks_is_pro() {
add_action(
'plugins_loaded',
function () {
// Load language files.
$path = dirname( plugin_basename( __FILE__ ) ) . '/languages';
load_plugin_textdomain( 'vk-blocks-pro', false, $path );
// サイトのロケールを取得
$locale = determine_locale();
// 翻訳ファイルのパスを指定
$path = plugin_dir_path( __FILE__ ) . 'languages';

// 日本語の設定のみ翻訳ファイルを読み込み
if ( strpos( $locale, 'ja' ) === 0 ) {
// PHPファイルの翻訳読み込み
load_textdomain( 'vk-blocks-pro', $path . '/vk-blocks-pro-ja.mo' );

// JavaScriptファイルの翻訳設定
add_action(
'wp_enqueue_scripts',
function () use ( $path ) {
// スクリプト登録後に翻訳設定
wp_set_script_translations( 'vk-blocks-build-js', 'vk-blocks-pro', $path );
wp_set_script_translations( 'vk-blocks-admin-js', 'vk-blocks-pro', $path );
}
);
}
}
);

Expand Down

0 comments on commit 6077c45

Please sign in to comment.