Reputation: 2878
I want to set language value of a gsp page dynamically . Currently I am just doing it using basic hardcoded value . I did find something with JS Onload event described here.
But I wanted to find something that is GSP driven . Is there any way ?
My current code looks like <html lang="en">
Upvotes: 1
Views: 373
Reputation: 8587
I think maybe you are thinking of this in a more complex way than it actuall is.
In grails you have your layouts/main.gsp which is your sitemesh.
The tag <html lang='en'
is declared at the very top of this
If you simply edit this page and add the following:
<g:set var="locale" value="${session?.'org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE'?:java.util.Locale.UK}"/>
<html lang="${locale?.language?:'en'}" class="no-js">
Then when I visit my site:
localhost:8080/?lang=ja_JP
view source shows:
<html lang="ja" class="no-js">
You need to do that for each sitemesh that requires to do this - having a read about this property it seems it doesn't do much for the browser but may help non human things such as search engines.
Upvotes: 2