WP_Theme_JSON_Resolver::translate( array $theme_json, string $domain = 'default' )
This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
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.
Parameters
- $theme_json
-
(array) (Required) The theme.json to translate.
- $domain
-
(string) (Optional) Text domain. Unique identifier for retrieving translated strings.
Default value: 'default'
Return
(array) Returns the modified $theme_json_structure.
Source
File: wp-includes/class-wp-theme-json-resolver.php
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; }
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/translate