Messages compiler for Play 2 Scala


In Play almost everything is evaluated at compile time. We thought why not add the conf/messages to the set of compiled sources and resources. So this simple Play plugin compiles the keys in conf/messages to valid Scala code. Instead of using string literals to refer to property keys, we can now use Scala literals. Misspelt keys are no longer an unnoticed issue and result in a compilation error.

// becomes


Add the following to project/plugins.sbt:

resolvers += "Tegonal releases" at ""

addSbtPlugin("com.tegonal" % "play-messagescompiler" % "1.0.3")


The file conf/messages will be compiled to target/scala*/src_managed/main/conf/messages.scala

Having a conf/messages file with the content

home.title=Space: the final frontier

results in the following example controller code:

package controllers

import play.api._
import play.api.mvc._
import conf.messages._

object Application extends Controller {

  def index = Action {


Please note the import of conf.messages._

play-messagescompiler is hosted on github: