1

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">

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
Abdullah Al Noman
  • 2,817
  • 4
  • 20
  • 35

1 Answers1

2

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.

V H
  • 8,382
  • 2
  • 28
  • 48
  • cool, ye sorry wasn't sure after answering if this was a deeper question lurking in the Javascript world due to the angle, anyhow hope you are through the hurdle :) – V H Nov 15 '17 at 14:48
  • Yeah just wanted something like this .. I did not want to use JS to modify the tag and add attribute .. Thanks – Abdullah Al Noman Nov 15 '17 at 14:55