How do I pass the language through ajax request
You will need to change the URL of your AJAX call to include the language prefix. So this:

url: "/gallery/view", 


Will be this:

url: "/ja/gallery/view",