Question

I have a weird problem.

I have a play application with several pages, and 3 different languages (my application.conf is like application.langs="es,en,fr")

I have 3 files, messages.en messages.fr messages.es

on my index page, everything works well. I have buttons to change the language and when I click the text changes like expected to the correct language.

Now I have another page, which should work exactly the same, it has the same buttons, calling the same functions, but the text never changes (it stays in french the whole time).

The weirdest thing is that when I look at the cookie, it is correct! When I click on the spanish button, the value of PLAY_LANG changes to es for example.

Any idea where this could come from? I checked my message.xx files as well as the @Messages("xxx") in both files. Everything looks the same...

Thanks, Vinkun

EDIT :

here is the code I use :

 def index = IsAuthenticated { name =>
   val user = User.findByEmail(name)
    implicit request =>
   Ok(views.html.index(loginForm, User.lastThree, user, ""))
}

def changeLanguage(lang:String) = Action { 
    request =>
    val referrer = request.headers.get(REFERER).getOrElse(HOME_URL)
   Redirect(referrer).withLang(Lang(lang))
}

def changeLanguageStory(lang:String) = Action { 
    request =>
    val referrer = request.headers.get(REFERER).getOrElse("/story")
   Redirect(referrer).withLang(Lang(lang))
}
def story = IsAuthenticated { name =>
   val user = User.findByEmail(name)
   implicit request =>
   Ok(html.story("enjoy the story", user))
}

with the routes used

GET     /index/:lang                controllers.Application.changeLanguage(lang: String)
GET     /story/:lang                controllers.Application.changeLanguageStory(lang: String)

application.conf

application.langs="fr,en,es"

and how I call the functions in index page

<a href="@routes.Application.changeLanguage("en")"><img src="/assets/images/UK.jpg" width="30px" height="20px"/></a>
<a href="@routes.Application.changeLanguage("fr")"><img src="/assets/images/France.jpg" width="30px" height="20px"/></a>
<a href="@routes.Application.changeLanguage("es")"><img src="/assets/images/Mexico.jpg" width="30px" height="20px"/></a>

in story page

<a href="@routes.Application.changeLanguageStory("en")"><img src="/assets/images/UK.jpg" width="30px" height="20px"/></a>
<a href="@routes.Application.changeLanguageStory("fr")"><img src="/assets/images/France.jpg" width="30px" height="20px"/></a>
<a href="@routes.Application.changeLanguageStory("es")"><img src="/assets/images/Mexico.jpg" width="30px" height="20px"/></a>

and of course I have the files messages messages.en messages.es messages.fr

On the index page, everything works fine. When I click one of the other language picture, it changes the language of the page accordingly. In the story page; it always takes the language of "messages" file, never the other languages, eventhough the PLAY_LANG cookie is modified correctly.

Thanks for your help

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top