Automattic\WooCommerce\Internal\Admin

Translations::combine_translation_chunk_files()publicWC 1.0

Combine translation chunks when files are updated.

This function combines JSON translation data auto-extracted by GlotPress from Webpack-generated JS chunks into a single file that can be used in subsequent requests. This is necessary since the JS chunks are not known to WordPress via wp_register_script() and wp_set_script_translations().

Method of the class: Translations{}

No Hooks.

Return

null. Nothing (null).

Usage

$Translations = new Translations();
$Translations->combine_translation_chunk_files( $instance, $hook_extra );
$instance(Language_Pack_Upgrader) (required)
Upgrader instance.
$hook_extra(array) (required)
Info about the upgraded language packs.

Translations::combine_translation_chunk_files() code WC 8.6.1

public function combine_translation_chunk_files( $instance, $hook_extra ) {
	if (
		! is_a( $instance, 'Language_Pack_Upgrader' ) ||
		! isset( $hook_extra['translations'] ) ||
		! is_array( $hook_extra['translations'] )
	) {
		return;
	}

	// Make sure we're handing the correct domain (could be woocommerce or woocommerce-admin).
	$plugin_domain = explode( '/', plugin_basename( __FILE__ ) )[0];
	$locales       = array();
	$language_dir  = WP_LANG_DIR . '/plugins/';

	// Gather the locales that were updated in this operation.
	foreach ( $hook_extra['translations'] as $translation ) {
		if (
			'plugin' === $translation['type'] &&
			$plugin_domain === $translation['slug']
		) {
			$locales[] = $translation['language'];
		}
	}

	// Build combined translation files for all updated locales.
	foreach ( $locales as $locale ) {
		// So long as this function is hooked to the 'upgrader_process_complete' action,
		// WP_Filesystem should be hooked up to be able to call build_and_save_translations.
		$this->build_and_save_translations( $language_dir, $plugin_domain, $locale );
	}
}