Automattic\WooCommerce\Internal\Admin
Translations::get_translation_chunk_data()
Find and combine translation chunk files.
Only targets files that aren't represented by a registered script (e.g. not passed to wp_register_script()).
Метод класса: Translations{}
Хуков нет.
Возвращает
Массив
. Combined translation chunk data.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_translation_chunk_data( $lang_dir, $domain, $locale );
- $lang_dir(строка) (обязательный)
- Path to language files.
- $domain(строка) (обязательный)
- Text domain.
- $locale(строка) (обязательный)
- Locale being retrieved.
Код Translations::get_translation_chunk_data() Translations::get translation chunk data WC 7.3.0
private function get_translation_chunk_data( $lang_dir, $domain, $locale ) { // So long as this function is called during the 'upgrader_process_complete' action, // the filesystem object should be hooked up. global $wp_filesystem; // Grab all JSON files in the current language pack. $json_i18n_filenames = glob( $lang_dir . $domain . '-' . $locale . '-*.json' ); $combined_translation_data = array(); if ( false === $json_i18n_filenames ) { return $combined_translation_data; } foreach ( $json_i18n_filenames as $json_filename ) { if ( ! $wp_filesystem->is_readable( $json_filename ) ) { continue; } $file_contents = $wp_filesystem->get_contents( $json_filename ); $chunk_data = \json_decode( $file_contents, true ); if ( empty( $chunk_data ) ) { continue; } if ( ! isset( $chunk_data['comment']['reference'] ) ) { continue; } $reference_file = $chunk_data['comment']['reference']; // Only combine "app" files (not scripts registered with WP). if ( false === strpos( $reference_file, WC_ADMIN_DIST_JS_FOLDER . 'app/index.js' ) && false === strpos( $reference_file, WC_ADMIN_DIST_JS_FOLDER . 'chunks/' ) ) { continue; } if ( empty( $combined_translation_data ) ) { // Use the first translation file as the base structure. $combined_translation_data = $chunk_data; } else { // Combine all messages from all chunk files. $combined_translation_data['locale_data']['messages'] = array_merge( $combined_translation_data['locale_data']['messages'], $chunk_data['locale_data']['messages'] ); } } // Remove inaccurate reference comment. unset( $combined_translation_data['comment'] ); return $combined_translation_data; }