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()).
Method of the class: Translations{}
No Hooks.
Return
Array
. Combined translation chunk data.
Usage
// private - for code of main (parent) class only $result = $this->get_translation_chunk_data( $lang_dir, $domain, $locale );
- $lang_dir(string) (required)
- Path to language files.
- $domain(string) (required)
- Text domain.
- $locale(string) (required)
- Locale being retrieved.
Translations::get_translation_chunk_data() Translations::get translation chunk data code WC 9.8.1
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; } // Use first JSON file to determine file format. This check is required due to // file format difference between official language files and user translated files. $format_determine_file = reset( $json_i18n_filenames ); if ( ! $wp_filesystem->is_readable( $format_determine_file ) ) { return $combined_translation_data; } $file_contents = $wp_filesystem->get_contents( $format_determine_file ); $format_determine_data = \json_decode( $file_contents, true ); if ( empty( $format_determine_data ) ) { return $combined_translation_data; } if ( isset( $format_determine_data['comment'] ) ) { return $this->combine_official_translation_chunks( $json_i18n_filenames ); } elseif ( isset( $format_determine_data['source'] ) ) { return $this->combine_user_translation_chunks( $json_i18n_filenames ); } else { return $combined_translation_data; } }