translate_settings_using_i18n_schema

函数
translate_settings_using_i18n_schema ( $i18n_schema, $settings, $textdomain )
Access
Private
参数
  • (string|string[]|array[]|object) $i18n_schema I18n schema for the setting.
    Required:
  • (string|string[]|array[]) $settings Value for the settings.
    Required:
  • (string) $textdomain Textdomain to use with translations.
    Required:
返回值
  • (string|string[]|array[]) Translated settings.
定义位置
相关方法
rest_validate_string_value_from_schemarest_validate_integer_value_from_schemarest_validate_boolean_value_from_schemarest_validate_object_value_from_schematranslations_api
引入
5.9.0
弃用
-

translate_settings_using_i18n_schema: 这个函数翻译一个使用WordPress Settings API的设置页面的选项。它是用来处理显示给用户的设置的翻译的。

使用其i18n模式翻译提供的设置值。

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

常见问题

FAQs
查看更多 >