By default there is no way to access the language through JS in Drupal 7. You could of course read the
lang attribute of the
<html> tag, but that is far from being an optimal solution.
Luckily, this is pretty easy to achieve through a custom module. Here's what you need to do:
- Hook into every page load - both front and back end.
- Get the current language code.
- Make it available as JS variable.
This code would go in
You can then access this in JS the following way:
Drupal 8 already includes this and you can use it the following way: