2

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

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

2 Answers 2

1

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 Commented Feb 28, 2020 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 Commented Feb 28, 2020 at 5:52
  • @pankajparmar you have run deploy command? and check this file pub/static/frontend/Your/Theme/<language>/js-translation.json Commented Feb 28, 2020 at 5:59
  • Have you added your string translation in i18 ar_SA.csv file? Commented Feb 28, 2020 at 6:09
  • @ShaileshKatarmal you need to add and then run deploy command and check Commented Feb 28, 2020 at 6:11
  • @ShaileshKatarmal yes,I have added string ar_SA.csv then execute all command. Commented Feb 28, 2020 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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