[2.0] i18n: Setting the default language

2,805 views
Skip to first unread message

Ólafur Gauti Guðmundsson

unread,
Feb 26, 2012, 3:26:53 PM2/26/12
to play-framework
Hi all,
In Play 1.2 I could set switch the application language by doing
Lang.set("en");
Is there a similar way to set the current language centrally in Play
2.0?
Or is the only way to store the selected language in a cookie, and
supply it as an argument to all Messages.get() calls?

Thanks for your help!
Best regards,
OGG

Julien Richard-Foy

unread,
Feb 26, 2012, 9:19:26 PM2/26/12
to play-fr...@googlegroups.com
In play 2 the default language is the one you use to write your conf/messages file (with no extension)

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>

Ólafur Gauti Guðmundsson

unread,
Feb 27, 2012, 5:48:50 AM2/27/12
to play-framework
Hi, thanks for your reply.
The thing is, I want to allow the user to switch the application to
another language.
In this case, it looks like I have to pass a new Lang(...) to each
call to Messages.get()?

This is why I was wandering whether I can override the language
centrally at runtime (as I could in Play 1.2: Lang.set(...))?

Thanks,
OGG

On Feb 27, 2:19 am, Julien Richard-Foy <j...@zenexity.com> wrote:
> In play 2 the default language is the one you use to write your conf/messages file (with no extension)
>

Guillaume Bort

unread,
Feb 27, 2012, 6:10:34 AM2/27/12
to play-fr...@googlegroups.com
Are you using the Java or the Scala API? In the Scala API you can
define your own implicit Lang with an higher priority.

2012/2/27 Ólafur Gauti Guðmundsson <oli....@gmail.com>:

--
Guillaume Bort

Ólafur Gauti Guðmundsson

unread,
Feb 27, 2012, 6:23:54 AM2/27/12
to play-framework
I am using the Java API. Are there any plans to allow this
functionality for Java as well?

Thanks!
OGG

On Feb 27, 11:10 am, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> Are you using the Java or the Scala API? In the Scala API you can
> define your own implicit Lang with an higher priority.
>
> 2012/2/27 Ólafur Gauti Guðmundsson <oli.ga...@gmail.com>:

Guillaume Bort

unread,
Feb 27, 2012, 6:50:16 AM2/27/12
to play-fr...@googlegroups.com
Yes, please report the issue in the bug tracker.

2012/2/27 Ólafur Gauti Guðmundsson <oli....@gmail.com>:

Federico Tolomei

unread,
Feb 27, 2012, 7:03:51 AM2/27/12
to play-fr...@googlegroups.com
+1 for this.

--
skype: effe.to

Ólafur Gauti Guðmundsson

unread,
Feb 27, 2012, 7:11:47 AM2/27/12
to play-framework
Great, thanks! I've created a ticket:
https://play.lighthouseapp.com/projects/82401/tickets/174-20-i18n-add-ability-to-define-implicit-lang-for-java-api

On Feb 27, 11:50 am, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> Yes, please report the issue in the bug tracker.
>
> 2012/2/27 Ólafur Gauti Guðmundsson <oli.ga...@gmail.com>:

Stefan

unread,
Mar 19, 2012, 4:20:34 AM3/19/12
to play-fr...@googlegroups.com
+1
in my opionion this is one of the most important missing parts, since it keeps me from developing multilingual pages. please fix that :)

>> >> > To post to this group, send email to play-framework@googlegroups.com.
>> >> > To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.


>> >> > For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups "play-framework" group.

>> > To post to this group, send email to play-framework@googlegroups.com.
>> > To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.


>> > For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.
>>
>> --
>> Guillaume Bort
>
> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.

> To post to this group, send email to play-framework@googlegroups.com.
> To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.


> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>

--
Guillaume Bort

Henrik Binggl

unread,
Mar 25, 2012, 6:23:04 AM3/25/12
to play-fr...@googlegroups.com
Any news concerning schedule for this feature?

Julien Richard-Foy

unread,
Mar 26, 2012, 6:58:04 AM3/26/12
to play-fr...@googlegroups.com
You can easily write your own code handling that. See e.g.
https://github.com/julienrf/chooze/blob/master/app/controllers/CookieLang.scala

Wim De Clercq

unread,
Mar 26, 2012, 8:15:21 AM3/26/12
to play-fr...@googlegroups.com
Can't do such thing with Java though.

I think the best you can do for now is create your own Messages class which extends - or delegates to - the real Messages class.
And in your own class you can get the language from the session / pathvariable / wherever you keep it, pass it on the the real class and return the result.
Reply all
Reply to author
Forward
0 new messages