How to set translations in javascripts for my plugin?
I have in my plugin :
- form.js : js script to do a custom validation on form fields
- js_lang.php : based on this stackoverflow post
- my-plugin-domain-fr_FR.po
In form.js, I use a var (msg_must_match) from js_lang.php
function inputsMatch( inputTypes, idInputReferring, idInputRepeat ){
var inputReferring = document.getElementById( idInputReferring );
var inputRepeat = document.getElementById( idInputRepeat );
var checkPasswordValidity = function() {
if (inputReferring.value != inputRepeat.value) {
inputRepeat.setCustomValidity( msg_must_match /*-- here*/ );
} else {
inputRepeat.setCustomValidity('');
}
};
inputReferring.addEventListener('change', checkPasswordValidity, false);
inputRepeat.addEventListener('change', checkPasswordValidity, false);
}
In my js_lang.php I try to manage the translation loading my-plugin-domain-fr_FR.po without success
$locale = "fr_FR";
putenv("LANG=".$locale);
setlocale('LC_ALL', $locale);
bindtextdomain("my-plugin-domain", "./locale/");
textdomain("my-plugin-domain");
$str = 'It is must match with the previous input';
?
msg_must_match = "?php echo gettext( $str ); ?"
I do not manage to load correctly the .po file. Someone could help me ? Is there a easier wordpress way to do this ?
Topic xgettext translation Wordpress javascript
Category Web