1

Does not translate a string in Arabic(ar_SA) Language, How to translate using jQuery?

require([
        "jquery",
        "mage/translate"
    ],
    function($,$t) {
        alert($t("hello"));
    });
0

Follow below step.

  1. Link the mage/translate library:

    define (['jquery', 'mage/translate'], function ($) {...});

  2. Use the $.mage.__('') function when adding a string:

    $.mage.__('<string>');

  3. 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!

1
  • I have also try this but it's not working any other solution then please tell me Feb 28 '20 at 5:39
0

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

6
  • I have also tried this but it's not working any other solution then please tell me Feb 28 '20 at 5:52
  • @pankajparmar you have run deploy command? and check this file pub/static/frontend/Your/Theme/<language>/js-translation.json Feb 28 '20 at 5:59
  • Have you added your string translation in i18 ar_SA.csv file? Feb 28 '20 at 6:09
  • @ShaileshKatarmal you need to add and then run deploy command and check Feb 28 '20 at 6:11
  • @ShaileshKatarmal yes,I have added string ar_SA.csv then execute all command. Feb 28 '20 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.