wp_set_script_translations

函数
wp_set_script_translations ( $handle, $domain = 'default', $path = '' )
参数
  • (string) $handle Script handle the textdomain will be attached to.
    Required:
  • (string) $domain Optional. Text domain. Default 'default'.
    Required:
    Default: 'default'
  • (string) $path Optional. The full file path to the directory containing translation files.
    Required:
    Default: (empty)
返回值
  • (bool) True if the text domain was successfully localized, false otherwise.
相关
  • WP_Scripts::set_translations()
定义位置
相关方法
load_script_translationswp_get_installed_translationswp_get_available_translations_get_path_to_translationwp_get_script_tag
引入
5.0.0
弃用
-

wp_set_script_translations: 这个函数为一个给定的脚本设置翻译。它接受脚本句柄和一个翻译数组,其中每个翻译是一个关联数组,以要翻译的字符串为键,以翻译后的字符串为值。

设置脚本的翻译字符串。

仅当脚本已注册时有效。

function wp_set_script_translations( $handle, $domain = 'default', $path = '' ) {
	global $wp_scripts;

	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
		_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
		return false;
	}

	return $wp_scripts->set_translations( $handle, $domain, $path );
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-05 14:32:54

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: