0

I am making ajax request , and I call __('string to translate') function on backend. The problem is that translate is not working at all. My ajax controller is implementing HttpPostActionInterface Interface to avoid massive data load. If I use previous way, i.e extending \Magento\Framework\App\Action\Action , the translation is working good, however I don't wan't to extend this huge class. Have anybody got idea why HttpPostActionInterface is not working with translations?

I've tried various things, including this here , however nothing seems to be working. I will do translations on frontend side eventually , but this doesn't explain why translations are missed on this interface?

2
  • Can you describe with code what you have try and where that not working. – Dhiren Vasoya Jan 15 at 11:33
  • I am making simple AJAX request and in backend controller I use $response['message'] = __('Translated text'); . The problem is that text is translated if I extend controller with \Magento\Framework\App\Action\Action , however it does not when controller is only implementing HttpPostActionInterface – BlueScrinn Jan 18 at 6:21
0

You need to use translate js for this:

require([
'jquery',
'jquery/ui', 
'mage/translate'
], function($){ 
    $.mage.__('Your text message for translation')
});

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.