Automattic\WooCommerce\Internal\Admin
Translations::combine_translation_chunk_files
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().
Метод класса: Translations{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$Translations = new Translations(); $Translations->combine_translation_chunk_files( $instance, $hook_extra );
- $instance(Language_Pack_Upgrader) (обязательный)
- Upgrader instance.
- $hook_extra(массив) (обязательный)
- Info about the upgraded language packs.
Код Translations::combine_translation_chunk_files() Translations::combine translation chunk files WC 10.4.3
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;
}
$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'] &&
self::$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, self::$plugin_domain, $locale );
}
}