Issue Details (XML | Word | Printable)

Key: GRAILS-3871
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Jeff Brown
Reporter: Jeff Brown
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Grails

the lang request parameter may not be working

Created: 23/Jan/09 09:54 AM   Updated: 18/Jan/10 11:05 AM   Resolved: 23/Jan/09 02:57 PM
Return to search
Component/s: None
Affects Version/s: 1.1-beta2
Fix Version/s: 1.1-beta3

Time Tracking:
Not Specified


 Description  « Hide

It looks like the lang request parameter isn't being respected.



Jeff Brown added a comment - 23/Jan/09 12:06 PM

It looks like the lang param works if a request is made to a controller but not otherwise. For example, if I surf to the root of my app which renders web-app/index.gsp, it doesn't look like it works there.


Jeff Brown added a comment - 23/Jan/09 02:57 PM

This is a known issue, been like that for a while. The solution is to root your view through a controller like:

"/"(controller:"foo")

and

def index = { render view:"/index" }


Christoph Lechleitner added a comment - 11/Jun/09 10:59 AM

Why is this a Won'f Fix?
If incoming users get the wrong language, changing it is the first click and usually happens in / which usually is a view.
A developer evaluating Grails as possible main web framework testing i18n usually does that in a minimal HelloWorld view and failing here can be a real show stopper!

If there are no immediate plans to fix this, at least the i18n documentation should mention this feature, with a single sentence in the according chapter:
http://grails.org/doc/1.1.1/guide/10.%20Internationalization.html#10.2 Changing Locales

To make it easier for the next Grails newby here are the details to get i18n working at /:

1. grails create-controller Home

2. in grails-app/conf/UrlMappings.groovy change ...
"/"(view:"/index")
.. to ...
"/"(controller:"home")
... and don't type "Home" instead of "home" here!

3. in grails-app/controllers/HomeController.groovy change the index method to ...
def index = { render view:"/index" }

4. put locale changing links in grails-app/views/index.gsp or grails-app/views/layouts/main.gsp or whereever, like this:
Switch to <g:link params="[lang:'en']">English</g:link> |
<g:link params="[lang:'de']">German</g:link> | ...

Hope this helps somebody ...


Christoph Lechleitner added a comment - 11/Jun/09 12:21 PM

There is yet another poorly documented feature that can drive you crazy when using i18n on a system not set to English, and I suppose this issue is a good place to spread that, too:

As this ...
http://www.groovy-forum.de/read.php?3,2931,3636#msg-3636
... Geman message explains, when switching to a language without an according message_<cc>.properties file, like English , grails usually falls back to the locale of the operation system environment, not to the language-less messages.properties file as one might expect.

This can be changed in grails-app/conf/Bootstrap.groovy by setting the bean messageSource's property fallbackToSystemLocale to false, like this:

def init = { servletContext -> def appContext = ServletContextHolder.getServletContext().getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT) def messageSource = appContext.getBean("messageSource") messageSource.fallbackToSystemLocale = false }

To avoid just another trap: Do not forget the imports:
import org.codehaus.groovy.grails.web.context.ServletContextHolder
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes

Forgetting imports in Bootstrap.groovy stops the app from a full start but and leaves process and TCP LISTENer alive, which makes the problem difficult to understand and solve especially when one is not used to "decrypt" java stacktraces in logfiles )


Erik Westra added a comment - 18/Jan/10 11:05 AM

As far as using the messages.properties file. I simply copied it to messages_en.properties and then used ?lang=en