WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Theme_JSON_Resolver::translate() private WP 5.8.0

Given a theme.json structure modifies it in place to update certain values by its translated strings according to the language set by the user.

Ищем WP-разработчика! Фулл-тайм, удаленка, хорошая зарплата, соц. пакет. Подробности.
Компания Boosta.

{} Это метод класса: WP_Theme_JSON_Resolver{}

Хуков нет.

Возвращает

Массив. Returns the modified $theme_json_structure.

Использование

$result = WP_Theme_JSON_Resolver::translate( $theme_json, $domain );
$theme_json(массив) (обязательный)
The theme.json to translate.
$domain(строка)
Text domain. Unique identifier for retrieving translated strings.
По умолчанию: 'default'

Список изменений

С версии 5.8.0 Введена.

Код WP_Theme_JSON_Resolver::translate() WP 5.8.2

private static function translate( $theme_json, $domain = 'default' ) {
	$fields = self::get_fields_to_translate();
	foreach ( $fields as $field ) {
		$path    = $field['path'];
		$key     = $field['key'];
		$context = $field['context'];

		/*
		 * We need to process the paths that include '*' separately.
		 * One example of such a path would be:
		 * [ 'settings', 'blocks', '*', 'color', 'palette' ]
		 */
		$nodes_to_iterate = array_keys( $path, '*', true );
		if ( ! empty( $nodes_to_iterate ) ) {
			/*
			 * At the moment, we only need to support one '*' in the path, so take it directly.
			 * - base will be [ 'settings', 'blocks' ]
			 * - data will be [ 'color', 'palette' ]
			 */
			$base_path = array_slice( $path, 0, $nodes_to_iterate[0] );
			$data_path = array_slice( $path, $nodes_to_iterate[0] + 1 );
			$base_tree = _wp_array_get( $theme_json, $base_path, array() );
			foreach ( $base_tree as $node_name => $node_data ) {
				$array_to_translate = _wp_array_get( $node_data, $data_path, null );
				if ( is_null( $array_to_translate ) ) {
					continue;
				}

				// Whole path will be [ 'settings', 'blocks', 'core/paragraph', 'color', 'palette' ].
				$whole_path       = array_merge( $base_path, array( $node_name ), $data_path );
				$translated_array = self::translate_theme_json_chunk( $array_to_translate, $key, $context, $domain );
				_wp_array_set( $theme_json, $whole_path, $translated_array );
			}
		} else {
			$array_to_translate = _wp_array_get( $theme_json, $path, null );
			if ( is_null( $array_to_translate ) ) {
				continue;
			}

			$translated_array = self::translate_theme_json_chunk( $array_to_translate, $key, $context, $domain );
			_wp_array_set( $theme_json, $path, $translated_array );
		}
	}

	return $theme_json;
}