Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

danielnixon/play-messagescompiler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

play-messagescompiler - Messages compiler for Play 2 Scala

Build Status Maven Central

Versions

play-messagescompiler version Play version
1.0.8 2.6.0-M1

About

This humble Play plugin provides type safety for the project's messages. It adds key literals instead of using strings to reference a property.

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

Using the generated key literals saves the trouble of misspelt keys that lead to non-translated properties. A nonexistent or changed key will lead to a compilation error.

Installation

Add the following to project/plugins.sbt:

addSbtPlugin("org.danielnixon" % "play-messagescompiler" % "1.0.7")

Usage

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

home.title=Space: the final frontier

After importing conf.messages._ the key literals are available within your code.

package controllers

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

object Application extends Controller {

  def index = Action {
    Ok(views.html.index(home.title))
  }

}

The plugin also supports message formats:

// conf/messages
home.title=Space: the final frontier, Stardate: {0}

// within a controller
Ok(views.html.index(home.title("44390.1")))

// where this wouldn't compile
Ok(views.html.index(home.title))

Ideas

  • Type checked java.text.MessageFormat arguments (number, date, time, choice).

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/

About

Messages compiler for Play 2 Scala

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 100.0%