Automattic\WooCommerce\Internal\Admin

Translations::generate_translation_strings()privateWC 1.0

Combine translation chunks when plugin is activated.

This function combines JSON translation data auto-extracted by GlotPress from Webpack-generated JS chunks into a single file. 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

// private - for code of main (parent) class only
$result = $this->generate_translation_strings();

Translations::generate_translation_strings() code WC 8.7.0

private function generate_translation_strings() {
	$plugin_domain = explode( '/', plugin_basename( __FILE__ ) )[0];
	$locale        = determine_locale();
	$lang_dir      = WP_LANG_DIR . '/plugins/';

	// Bail early if not localized.
	if ( 'en_US' === $locale ) {
		return;
	}

	if ( ! function_exists( 'get_filesystem_method' ) ) {
		require_once ABSPATH . 'wp-admin/includes/file.php';
	}

	$access_type = get_filesystem_method();
	if ( 'direct' === $access_type ) {
		\WP_Filesystem();
		$this->build_and_save_translations( $lang_dir, $plugin_domain, $locale );
	} else {
		// I'm reluctant to add support for other filesystems here as it would require
		// user's input on activating plugin - which I don't think is common.
		return;
	}
}