play framework sometimes failed to read language files

39 Views Asked by At

I use playframework 2.3.x and have Russian and English languages. The problem is that the email sometimes can get the values from the language files.

For example, in the file, i have mail.subject=welcome to our platform. it sometimes just sent the "mail.subject" instead of "welcome to our platform". Please advise how to solve this problem?

def sendEmail(to: String) {
try {
  var fromAddress = current.configuration.getString("smtp.from").get
  val bcc = current.configuration.getString("smtp.bcc").get
  val email = Email(
    Messages.get(getLan(), "mail.subject"),
    fromAddress,
    Seq(to),
    bodyHtml = Some(views.html.custom.mails.application().toString()),
    bcc = Seq(bcc)
  )
  MailerPlugin.send(email)
} catch {
  case ex: Exception => PlayLogger.instance.error(ex.getMessage)
}
}
1

There are 1 best solutions below

0
Andriy Kuba On

mail.subject key is not defined for some language that you use, and that language is set in the request cookie.

Play, by default, take language from the cookie. The default language is selected if no language in a cookie was found or that language is not acceptable.

https://github.com/playframework/playframework/blob/2.3.x/framework/src/play/src/main/scala/play/api/mvc/Controller.scala#L64

You can fix it by set the language explicitly or create your own language detection.