【发布时间】:2017-09-19 05:20:12
【问题描述】:
我正在使用未准备好 WPML 的活动监视器插件,我需要在 javascript 文件中翻译错误消息。这是 app.js 文件中的代码块
function cmApp_validateForm()
{
var signupContainerElem=jQuery("#cmApp_signupContainer");
var errorElem = jQuery("#cmApp_emailError");
var errorElemDOB = jQuery("#cmApp_dobError");
var formElem = signupContainerElem.find("form");
var processingMsgElem = signupContainerElem.find("div.cmApp_processingMsg");
var successMsgElem = signupContainerElem.find("div.cmApp_successMsg");
var errorMsgAr=[];
var errorFieldSelectorAr=[];
var errorMsg="";
formElem.hide();
errorElem.html("").hide();
errorElemDOB.html("").hide();
successMsgElem.hide();
cmApp_showProcessing();
signupContainerElem.find("input,select").css("outline","none");
// validate the email field. make sure it is not empty and that it is valid. if invalid, add to the error array and outline the field in red
var email = jQuery("#cmApp_signupEmail").val();
if (email.length < 1) {
errorMsg = "Geef een geldig e-mailadres in";
errorMsgAr[errorMsgAr.length]="Please provide correct email";
jQuery("#cmApp_signupEmail").focus().css("border" , "2px solid #D95350");
}
else {
if (!cmApp_validateEmail(email)) {
errorMsgAr[errorMsgAr.length]="This is an invalid email";
errorFieldSelectorAr[errorFieldSelectorAr.length]="#cmApp_signupEmail";
jQuery("#cmApp_signupEmail").focus().css("border","2px solid #D95350");
}
},
我尝试使用此示例进行翻译,以使其在 sting 翻译中可用。
// Register the script
wp_register_script( 'some_handle', 'path/to/myscript.js' );
// Localize the script with new data
$translation_array = array(
'some_string' => __( 'Some string to translate', 'plugin-domain' ),
'a_value' => '10'
);
wp_localize_script( 'some_handle', 'object_name', $translation_array );
// Enqueued script with localized data.
wp_enqueue_script( 'some_handle' );
但我不明白我应该填写什么“一些句柄”以及对象名应该是什么?或者有什么简单的翻译方法吗?
谁能解释我如何翻译这些错误文本?
提前谢谢你。
【问题讨论】:
标签: javascript wordpress wpml