4
votes

I have 2 problems. One has to do with the scala code and the other one with html. I'm trying to translate my website in Dutch and English. When my browser has Dutch as preferred language it displays the site in Dutch. But if I have English as preferred language it also displays the site in Dutch.

application.conf

play.i18n.langs = [ "en", "nl" ]

messages.en

login.title=Login
error.required=Field is required.
error.email.required=A valid email adress is required.

messages.nl

login.title=Inloggen
error.required=Dit veld is verplicht.
error.email.required=Een geldig e-mailadres is vereist.

LogIn.scala snippets

import play.api.i18n.Messages.Implicits._

object LogIn extends Controller{

val logInForm = Form(mapping(
"email" -> text.verifying(Messages("error.email.required"), {_.contains('@')}),
"password" -> text.verifying(Messages("error.required"), {!_.isEmpty})
))
}

What do I do wrong? How can I display my site in English

The other problem has to do with html. The playframework website said to write &{'key'} but this doesn't seem to work.

<h1 class="title">&{'login.title'}</h1>

This displays "&{'login.title'}" and not "Login" or "Inloggen" How does html read the messages files?

UPDATE: I discovered that instead of &{'login.title'} I can do the following:

@import play.i18n._

<h1>@Messages.get("login.title")</h1>

This reads from the messages file, but still only in Dutch and not in English

I use Intellij with Scala and Play Framework 2.4 all are the latest version.

1
I moved your solution to a community wiki answer. - Cœur

1 Answers

0
votes

Solution by OP.

Aside from changing the browsers preferred languages, I also changed the systems preferred language and restarted my computer. This seemed to fix the problem. My site now displays English.