Friday, September 12, 2008

How to change the locale in Grails.

It's simple to change the locale in Grail,just need put a param after you url.A better method is put a link in your template file,and include it in every your page,then write following code:

<span>

<g:link controller="${params.controller}" action="${params.action}" params="[lang:'en']" class="menuButton">English</g:link>

</span>

<span>

<g:link controller="${params.controller}" action="${params.action}" params="[lang:'de']" class="menuButton">German</g:link>

</span>



then you will have a change language in every page.or another way you can put this code in your layout.gsp file directly.

6 comments:

davala said...

vlw

Anonymous said...

Perfect. Thank you for the tip. Implemented Swedish English locale change using your tip.

www.absolutinvandrare.com

Anonymous said...

I'm having a problem...

Suppose you are in a show page, if you change the language in that page, then I receive an error and I loose the rest of the params that were in the map.
Do you know how I can solve this?

By the way, it was really helpful.

Thanks in advance.

Mariano Capurro said...

For the show page to work you have to add id="${params.id}" to the g:link tag.

Unknown said...

Hi I have a question, did you know how to autodetect client browser region settings using grails?

your answers will be much appreciated. tnx alot.

Rachat de credit said...

Thanks a ton it was a very good support, now to change the locale in grails. is definitely very easy with your recommendation. Thank you