|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Change i18n locale from a controller before calling the viewHello everyone,
I have a simple problem I don't know how to resolve. I get the params.lang = 'en' from the user, but within the controller we detect where the IP comes from and depending on that, we want to change the locale from 'en' to whatever the language corresponds to the geographic location of the user. For instance, if we want the view to be rendered in Spanish, just by simply setting lang = 'es' in the controller code does not do anything. The view is still being rendered in English 'en'. Anyone knows how to use the u18n support in Grails to change a locale within a controller before the view is called? Thanks a million! |
|
|
Re: Change i18n locale from a controller before calling the viewHello guys,
I found the answer myself. I want to post it here in case someone else has the same need in the future. The controller code would look like this: import org.springframework.web.servlet.support.RequestContextUtils as RCU class myController { def index = { 'Let's change the Locale to, let's say... 'es_ES' def newLocale = new Locale('es', 'ES') RCU.getLocaleResolver(request).setLocale(request, response, newLocale) 'DONE! Now when the view is rendered, it'll be done using the new locale } } |
|
|
Re: Change i18n locale from a controller before calling the viewGood job!
But I was wondering if you'd mind sharing the code for the nation ip lookup? :D Moe |
|
|
|
|
|
Re: Change i18n locale from a controller before calling the viewThen the ip would resolve to the country proxy server is located in.
On Sat, Jul 4, 2009 at 8:14 PM, Finn Herpich <finn.herpich@...> wrote: What about proxy-users? e.g. the tor-network? -- Most of what we call management consists of making it difficult for people to get their work done. |
|
|
Re: Change i18n locale from a controller before calling the viewSure,
We are using google maps in our website so we have a key to use google APIs. Once you have yours, you add the following code in the web page: <script type="text/javascript"> // Detects country by IP google.setOnLoadCallback(function() { if (google.loader.ClientLocation) { currentCountry = google.loader.ClientLocation.address.country_code; } else { //Can't find location } }); </script> Apart from the country code, you can get other area info too, but we only need the country. Our page redirects to the main page of our site, adding the country code as a param. On the server side we have a table in a database with all countries and the languages spoken in each one of them. You get the country code, look up the table, get the language code, and set the proper locale before calling the view (as I posted in my previous response) Alex
|
| Free embeddable forum powered by Nabble | Forum Help |