简体   繁体   中英

Play 2.6 I18N Twirl fails in production mode

When I run my Play 2.6 app in dev mode, it's properly localized to the requested language. However in production mode the placeholders for messages are not replaced with their actual values. In other words:

in messages.en I have:

home.location = Germany

In my Twirl template I have:

@()(implicit messages: MessagesProvider)
...
<span>@messages.messages("home.location")</span>

And in controller:

class HomeController @Inject()(components: ControllerComponents, langs: Langs)
    extends AbstractController(components)
    with I18nSupport {

  def home: Action[AnyContent] = Action { implicit request =>
    Ok(views.html.home())
  }
}

When I run in dev mode, it's rendered as

<span>Germany</span>

But in prod mode as:

<span>home.location</span>

This happens when I run in prod mode in SBT and also when I package it with sbt-native-packager and run standalone. Am I holding it wrong?

You have to put "LauncherJarPlugin" option in build.sbt.

For example, "lazy val root = (project in file (". ")). EnablePlugins (PlayScala, LauncherJarPlugin)"

I had the same problem, but I fixed it like this.

Good luck.

I faced more or less the same issue today. I have messages and messages.pt-br on my play application. everything was working fine on dev mode but on production only the English ( messages file) was being loaded. I noticed that on my application.conf file I had:

play.i18n.langs = [ "en", "pt-BR"]

but my pt-br file was named messages.pt-br . What I did was to rename it to messages.pt-BR and now it works just fine on production. I suspect the upper case letters in the filename play a big part of it on production.

Try to name them with the language extension exactly like in the application.conf and see if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM