'[2.0.x] internationalization not working

197 views
Skip to first unread message

sas

unread,
May 21, 2012, 1:05:55 AM5/21/12
to play-framework
I have a conf/messages file and a conf/messages.es-ar file

in application.conf I have:

# The application languages
# ~~~~~
application.langs="es-ar"

The browser is sending:

Accept-Language es-ar,en-us;q=0.7,en;q=0.3

But Play is using the conf/messages instead of conf/messages.es-ar

Am I missing something?


ps: moreover, it would be nice to define a conf/messages.es for all es-
* languajes

saludos

sas


Manuel Bernhardt

unread,
May 21, 2012, 11:42:54 AM5/21/12
to play-fr...@googlegroups.com
Hi sas,

in what place do you get this? i18n has worked nicely so far in my experience.

Manuel
> --
> 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.
>

JuDe

unread,
May 21, 2012, 1:03:42 PM5/21/12
to play-fr...@googlegroups.com
Hello sas,

I had quite similar problem earlier. Thanks to the community, the problem was solved.
Do you write on top of your views pages this line : @()(implicit lang: Lang) ?
The first brackets may be filled with "explicit" parameters but even if you don't have such parameters, you still have to write empty brackets or it won't work. And of course, implicit lang parameter is required for @Messages working properly.

Saludos!

sas

unread,
May 21, 2012, 10:16:56 PM5/21/12
to play-framework
Hi JuDe

thank for the tip

but it didn't work

I tried with a couple of more tests, like

<p>@Messages("index.title")(Lang("es"))</p>
<p>@Messages("index.title")(Lang("es-ar"))</p>
<p>@Messages("index.title")(lang)</p>

And the problems seems to be that lang = Lang("en-US")

even though the request is sending
Accept-Language es-ar,en-us;q=0.7,en;q=0.3

and

Accept-Language:es,en-US;q=0.8,en;q=0.6

(testing it with Firefox and chrome)

any idea?

saludos

sas

Manuel Bernhardt

unread,
May 22, 2012, 2:44:05 AM5/22/12
to play-fr...@googlegroups.com
All those languages are defined in the activate application.conf, or
not? I got bitten once by not defining one of them and wondering why
there was a fallback on messages all the time.

Manuel

biesior

unread,
May 22, 2012, 3:54:10 AM5/22/12
to play-fr...@googlegroups.com
ellou' sas

that's little bit weird, I've just tested some cases, and everything is correct:

added these languages to conf:

application.langs="es-ar,es-cl,es,en,pl"

created files
messages.es
messages.es-ar
messages.es-cl
etc

And when switching language order in firefox' preferencies the messages changes, to the first available one.
Also tested this in my view:

<p>@Messages("constraint.min")(Lang("es"))</p>
<p>@Messages("constraint.min")(Lang("es-ar"))</p>
<p>@Messages("constraint.min")(Lang("es-cl"))</p>
<p>@Messages("constraint.min")(Lang("en"))</p>
<p>@Messages("constraint.min")(Lang("pl"))</p>

it displays me the message in 5 "languages": Spanish, Spanish-Argentina, Spanish-Chille, English, Polish

sas

unread,
May 22, 2012, 7:34:01 AM5/22/12
to play-framework
Sorry, reading my post I realize it was a bit confusing

<p>@Messages("index.title")(Lang("es"))</p>
<p>@Messages("index.title")(Lang("es-ar"))</p>
<p>@Messages("index.title")(lang)</p>

the first two lines correctly picks the messages.es and messages.es-ar
file

but the last one picks messages, even though the browser sends an
accept-language fo es, and es-ar

Shall I have to pass something from the controller?

saludos

sas

this is my application.conf

# The application languages
# ~~~~~
application.langs="es,es-ar,en"

This is the project (I created a lang-test branch)

https://github.com/Nardoz/RestOpenGov/tree/lang-test/PlayBafici

application.conf: https://github.com/Nardoz/RestOpenGov/blob/lang-test/PlayBafici/conf/application.conf

the view i'm testing: https://github.com/Nardoz/RestOpenGov/blob/lang-test/PlayBafici/app/views/index.scala.html

JuDe

unread,
May 22, 2012, 5:43:12 PM5/22/12
to play-fr...@googlegroups.com
Maybe you could try without any (lang) at all, since it's an implicit parameter. 
At least if you wrote this at the first line of your view :  @()(implicit lang: Lang)

In your case in the body:  <p>@Messages("index.title")</p> 

Reply all
Reply to author
Forward
0 new messages