WP_Theme_JSON_Resolver::translate() WordPress Method

The WP_Theme_JSON_Resolver::translate() method is used to translate a string from one language to another. This is useful for making your theme more accessible to international users.

WP_Theme_JSON_Resolver::translate( array $theme_json, string $domain = 'default' ) #

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'


Top ↑

Return

(array) Returns the modified $theme_json_structure.


Top ↑

Source

File: wp-includes/class-wp-theme-json-resolver.php

	protected static function translate( $theme_json, $domain = 'default' ) {
		if ( null === static::$i18n_schema ) {
			$i18n_schema         = wp_json_file_decode( __DIR__ . '/theme-i18n.json' );
			static::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema;
		}

		return translate_settings_using_i18n_schema( static::$i18n_schema, $theme_json, $domain );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.