Friday, September 4, 2009

Grails i18n

Got a little bit pissed of regarding language changing on Grails.

Of the information I can find about it it should be fairly straightforward. Just providing the parameter "lang=xx". In my experience this works sometimes, but sometimes something magical happen running on Glassfish for a while. The switcing of language stops working. Don't know if this is a known problem.

Anyway, for now I made a workaround using the following code:
def beforeInterceptor = [action:this.&checkLang, except:['']]

    def checkLang() {
        if(session["lang"] == null){
            session["lang"] = "sv"
        }
        if(params.lang){
            session["lang"] = params.lang
        }
       if(params.lang && params.lang=="en"){
            def defaultLocale = new Locale("en","US")
            java.util.Locale.setDefault(defaultLocale)
       }         return
    }

Which works for now. Should think there is a better solution. Feel free to inform me if you know.

No comments:

Post a Comment