Does not translate a string in Arabic(ar_SA) Language, How to translate using jQuery
?
require([
"jquery",
"mage/translate"
],
function($,$t) {
alert($t("hello"));
});
Follow below step.
Link the mage/translate library:
define (['jquery', 'mage/translate'], function ($) {...});
Use the $.mage.__('') function when adding a string:
$.mage.__('<string>');
If your string contains a variable, to add a placeholder for this variable to the string stored in the dictionary, use the syntax similar to the following:
$.mage.__('Hello %1').replace('%1', yourVariable);
I hope it helps!
You can translate js error message Below way this
require([
'jquery', // jquery Library
'jquery/ui', // Jquery UI Library
'mage/translate' // Magento text translate (Validation message translte as per language)
], function($){
$(window).load(function() {
alert($.mage.__('hello'));
});
});
Magento2 use
mage/translate.js
for translation
pub/static/frontend/Your/Theme/<language>/js-translation.json
Commented
Feb 28, 2020 at 5:59