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 10.3.4
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;
}
}