translate_settings_using_i18n_schema()WP 5.9.0

Translates the provided settings value using its i18n schema.

Хуков нет.

Возвращает

Строку|Строку[]|Массив[]. Translated settings.

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

translate_settings_using_i18n_schema( $i18n_schema, $settings, $textdomain );
$i18n_schema(строка|string[]|array[]|объект) (обязательный)
I18n schema for the setting.
$settings(строка|string[]|array[]) (обязательный)
Value for the settings.
$textdomain(строка) (обязательный)
Textdomain to use with translations.

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

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

Код translate_settings_using_i18n_schema() WP 6.0

function translate_settings_using_i18n_schema( $i18n_schema, $settings, $textdomain ) {
	if ( empty( $i18n_schema ) || empty( $settings ) || empty( $textdomain ) ) {
		return $settings;
	}

	if ( is_string( $i18n_schema ) && is_string( $settings ) ) {
		return translate_with_gettext_context( $settings, $i18n_schema, $textdomain );
	}
	if ( is_array( $i18n_schema ) && is_array( $settings ) ) {
		$translated_settings = array();
		foreach ( $settings as $value ) {
			$translated_settings[] = translate_settings_using_i18n_schema( $i18n_schema[0], $value, $textdomain );
		}
		return $translated_settings;
	}
	if ( is_object( $i18n_schema ) && is_array( $settings ) ) {
		$group_key           = '*';
		$translated_settings = array();
		foreach ( $settings as $key => $value ) {
			if ( isset( $i18n_schema->$key ) ) {
				$translated_settings[ $key ] = translate_settings_using_i18n_schema( $i18n_schema->$key, $value, $textdomain );
			} elseif ( isset( $i18n_schema->$group_key ) ) {
				$translated_settings[ $key ] = translate_settings_using_i18n_schema( $i18n_schema->$group_key, $value, $textdomain );
			} else {
				$translated_settings[ $key ] = $value;
			}
		}
		return $translated_settings;
	}
	return $settings;
}