I have an ajax function in the javascript file that calls for the data in a custom module. But the problem is it always get the data for the default language. In my case it is 'en'. How do I get the data for another language.
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
This method always returns the default language for ajax requests. How do I get the data for the language that is mentioned in the url.
ajax:
$.ajax({
url: "/gallery/view",
method :'POST',
data: {
category : category,
propertyId : propertyId,
isCorporate : isCorporate,
brandId : brandId,
},
success: function(result){}
});
routing :
eme_gallery.view:
path: '/gallery/view'
defaults:
_controller: 'Drupal\eme_gallery\Controller\ViewGalleryImage::view'
_title: 'Image Gallery'
requirements:
_permission: 'access content'