load_woocommerce_core_js_translation()WC 1.0

WordPress will look for translation in the following order:

  • wp-content/plugins/woocommerce-blocks/languages/woo-gutenberg-products-block-{locale}-{handle}.json
  • wp-content/plugins/woocommerce-blocks/languages/woo-gutenberg-products-block-{locale}-{md5-handle}.json
  • wp-content/languages/plugins/woo-gutenberg-products-block-{locale}-{md5-handle}.json

We check if the last one exists, and if it doesn't we try to load the corresponding JSON file from the WC Core.

Хуков нет.

Возвращает

Строку|false. Path to the translation file to load. False if there isn't one.

Использование

load_woocommerce_core_js_translation( $file, $handle, $domain );
$file(строка|false) (обязательный)
Path to the translation file to load. False if there isn't one.
$handle(строка) (обязательный)
Name of the script to register a translation domain to.
$domain(строка) (обязательный)
The text domain.

Код load_woocommerce_core_js_translation() WC 7.7.2

function load_woocommerce_core_js_translation( $file, $handle, $domain ) {
	if ( 'woo-gutenberg-products-block' !== $domain ) {
		return $file;
	}

	$lang_dir = WP_LANG_DIR . '/plugins';

	/**
	 * We only care about the translation file of the feature plugin in the
	 * wp-content/languages folder.
	 */
	if ( false === strpos( $file, $lang_dir ) ) {
		return $file;
	}

	// If the translation file for feature plugin exist, use it.
	if ( is_readable( $file ) ) {
		return $file;
	}

	global $wp_scripts;

	if ( ! isset( $wp_scripts->registered[ $handle ], $wp_scripts->registered[ $handle ]->src ) ) {
		return $file;
	}

	$handle_src      = explode( '/build/', $wp_scripts->registered[ $handle ]->src );
	$handle_filename = $handle_src[1];
	$locale          = determine_locale();
	$lang_dir        = WP_LANG_DIR . '/plugins';

	// Translations are always based on the unminified filename.
	if ( substr( $handle_filename, -7 ) === '.min.js' ) {
		$handle_filename = substr( $handle_filename, 0, -7 ) . '.js';
	}

	$core_path_md5 = md5( 'packages/woocommerce-blocks/build/' . $handle_filename );

	/**
	 * Return file path of the corresponding translation file in the WC Core is
	 * enough because `load_script_translations()` will check for its existence
	 * before loading it.
	 */
	return $lang_dir . '/woocommerce-' . $locale . '-' . $core_path_md5 . '.json';
}