I installed FOSJsRouting but my route need _locale
parameter. How can I do that in JS ? Is there a way to get the locale in js ?
In twig, I can do app.request.attributes.get('_locale')
but in JS, I don't find any documentation.
$.ajax({
type : 'get',
url : Routing.generate('get_credits', {'_locale': app.request.attributes.get('_locale'), 'amount' : amount, 'monthNumber' : month }),
beforeSend : function(){
console.log('loading');
},
success: function(data){
},
error : function(){
}
});
What I usually do is set the locale as a html-tag attribute
<html lang="{{ app.request.locale }}">
which results in
<html lang="EN">
This is also useful for SEO, and you can always get the locale in JS by calling
$('html').attr('lang');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With