[2.1 - java] How change language to use in templates

456 views
Skip to first unread message

Adis

unread,
Feb 11, 2013, 2:52:35 PM2/11/13
to play-fr...@googlegroups.com
Hi,

I am pretty confused how to change the language in a Play 2.1 application. In 1.2 you used : 

Lang.change("");

But in 2.1, this is much harder. What I MUST have in my webapp (sell and buy platform that I am about to build): 

On the frontpage the user can choose his language, but how to change this in the application, so that I get the correct language back when I call the Message class from the controller or template?

When the user changed his language he can buy something from another user whose language can be completely different. So when I want to inform both users, I should call:

Messages.get(new Lang(user.getLanguage()), "my.translation.key");

I have seen this pull request by Julien: https://github.com/playframework/Play20/pull/325, but no idea how to use it in my Play Java App?

Thanks!

Nilanjan Raychaudhuri

unread,
Feb 11, 2013, 3:33:15 PM2/11/13
to play-fr...@googlegroups.com
Invoke the changLang method from inside the controller?

Nilanjan, Developer & Consultant
Typesafe Inc.
Twitter: @nraychaudhuri

Adis

unread,
Feb 11, 2013, 4:16:23 PM2/11/13
to play-fr...@googlegroups.com
Just like Nilanjan said, it can be done with method similir to 1.2.5 :-)


public static Result change(String langCode) {

    changeLang(langCode);

    Logger.info(Messages.get(new Lang(Lang.forCode("ru")), "welcome"));

     return ok(index.render("welcome"));

    }


method changeLang() will change the applications Language.

Reply all
Reply to author
Forward
0 new messages