Messages compiler for Play 2 Scala

Motivation

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.

Messages("home.title")
// becomes
home.title

Installation

Add the following to project/plugins.sbt:

resolvers += "Tegonal releases" at "https://github.com/tegonal/tegonal-mvn/raw/master/releases"

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

Usage

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 {
    Ok(views.html.index(home.title))
  }

}

Please note the import of conf.messages._

play-messagescompiler is hosted on github: https://github.com/tegonal/play-messagescompiler