Skip to content

Commit

Permalink
Update to play 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Karel Cemus committed Sep 23, 2020
1 parent 9056fbb commit 7c48402
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ env:
- secure: kHtHIFpZw8snrvs9SW4jl/wgd4YF2/DIJ0W9ueGdwzEWDcTnFK+8AVxYT0Ee5hfYDprna4lWKNClERWJKw5eSfCPQpoGbbULdz5f0b6/sVEAKmGCVAGPwkfkS0pRoOIaIT04rrK2I725VGx1JLo8JWSkLCWy/DmGzhBdp1tGONoFVsADlSvLSoG1zh+qey5p4kdFZT5O3t8tUo1OTQIoi3dXuIJVUuAML3a4BW/brM6LKizNxdMuytnWLSavEMAFggQHvodV+TIxVjXy8XXLPcpEi+KU6g5CPr+IVkW/xvjRsgQt933NaLZKMDJXCvhBiL5h8MuXg+rJnzsLPXPKzHwVFNquxBphm3fFNqBZReKb0fcgaOBG5wyRlasp6JqTPXH0j+pWNpXfpwg5OynKoDeJmgb4mmfK11HzNFuTL7YgIlU8OtDQPYR2xOvZ9LxBam1a9G0j1aJ98eERuJBBzR1bXlbidjKLZuJX7hKo9isqEuHdZKOefuDaH0QORiLJzsqt23Omy8cIN/QWu9Vsfq8zEMxsLPYRS2FRF7GfqGs5Xy0E0kqSIAoXKMb5i/CZ3ni7Hw3UapTkDx7SCVG/Oxybh6AwhAaZp/UjFOGcYIqyxmISz1d8Aad+qeCHv4GKl0q3MwGvCPNyirRVecs2TPsS0UA3SlcAW3MetrcxmtY=
- COURSIER_CACHE="$HOME/.coursier"
# set version of JDK
- [email protected]
- SCALA_VERSION=2.13.1

before_install:
- curl -Ls https://git.io/jabba | bash && . ~/.jabba/jabba.sh

install:
- export TRAVIS_JDK=`jabba ls-remote|\grep '[email protected].' | sort|tail -n 1`
- echo "Will use java $TRAVIS_JDK"
- jabba install "$TRAVIS_JDK" && jabba use "$TRAVIS_JDK" && java -Xmx32m -version

before_script:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">Multi-format Messaging module<br/> for Play framework</h1>

**Note: This version supports Play framework 2.7.x. For compatibility with previous versions see previous releases.**
**Note: This version supports Play framework 2.8.x. For compatibility with previous versions see previous releases.**

[Play framework 2](http://playframework.com/) is delivered with default Messaging module using property
files. The syntax is not much convenient as involves a lot of repetition, thus this module delivers
Expand All @@ -15,7 +15,7 @@ To your SBT `build.sbt` add the following lines:
```scala
libraryDependencies ++= Seq(
// YAML localization module
"com.github.karelcemus" %% "play-i18n" % "2.0.0"
"com.github.karelcemus" %% "play-i18n" % "2.1.0"
)
```

Expand Down
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ description := "Messaging localization plugin for the Play framework 2"

organization := "com.github.karelcemus"

scalaVersion := "2.13.1"
scalaVersion := "2.13.3"

crossScalaVersions := Seq( scalaVersion.value, "2.12.10", "2.11.12" )
crossScalaVersions := Seq( scalaVersion.value, "2.12.12" )

val playVersion = "2.7.3"
val playVersion = "2.8.2"

val specs2Version = "4.7.1"
val specs2Version = "4.10.3"

libraryDependencies ++= Seq(
// play framework cache API
"com.typesafe.play" %% "play" % playVersion % "provided",
// YAML parser, Java library
"org.yaml" % "snakeyaml" % "1.25",
"org.yaml" % "snakeyaml" % "1.27",
// test framework
"org.specs2" %% "specs2-core" % specs2Version % "test",
// test module for play framework
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.2
sbt.version=1.3.13
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// library release
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.11")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")

// PGP signature
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1")

// checks for updates
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.4.2")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.5.1")
6 changes: 3 additions & 3 deletions src/main/scala/play/ext/i18n/MessageFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected[i18n] object MessageFile {
case None => second
}

def apply(languages: Traversable[Lang], format: Format)(implicit configuration: Configuration, env: Environment): Traversable[MessageFile] =
def apply(languages: Iterable[Lang], format: Format)(implicit configuration: Configuration, env: Environment): Iterable[MessageFile] =
fileNames.map(name => languages.flatMap(apply(_, format, name))).reduce(_ ++ _)

def apply(lang: Lang, format: Format, name: String)(implicit configuration: Configuration, env: Environment): Iterable[MessageFile] = {
Expand All @@ -51,9 +51,9 @@ protected[i18n] object MessageFile {
)
}

def apply(format: Format)(implicit configuration: Configuration, env: Environment): Traversable[MessageFile] =
def apply(format: Format)(implicit configuration: Configuration, env: Environment): Iterable[MessageFile] =
fileNames.map { name =>
Traversable(
Iterable(
MessageFile("default", s"$name${format.toSuffix}", format.loader),
MessageFile("default.play", s"$name${format.toSuffix}.default", format.loader)
)
Expand Down
37 changes: 18 additions & 19 deletions src/main/scala/play/ext/i18n/MultiFormatMessagesModule.scala
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
package play.ext.i18n

import javax.inject.{Inject, Singleton}

import javax.inject.{Inject, Provider, Singleton}
import play.api.i18n._
import play.api.inject.Module
import play.api.inject.{Binding, Module}
import play.api.{Configuration, Environment}

import play.ext.i18n.MessagesLoaders._

/** Messaging plugin for parsing files in various different formats
*
* @author Karel Cemus
*/
*
* @author Karel Cemus
*/
@Singleton
class MultiFormatMessagesApi @Inject()(implicit environment: Environment, configuration: Configuration, langs: Langs) extends DefaultMessagesApi(messages = {

implicit val config = configuration
implicit val env = environment
class MultiFormatMessagesApiProvider @Inject()(implicit environment: Environment, configuration: Configuration, langs: Langs) extends Provider[MessagesApi] {

/** all files regardless the format */
def allFiles: List[MessageFile] = enabledFormats.flatMap(format => MessageFile(format) ++ MessageFile(langs.availables, format))
private def allFiles: List[MessageFile] = enabledFormats.flatMap(format => MessageFile(format) ++ MessageFile(langs.availables, format))

/** enabled loaders, disabled are dropped */
def enabledFormats: List[Format] = supportedFormats.filter(_.isEnabled(configuration.get[Configuration]("play.i18n.formats")))
private def enabledFormats: List[Format] = supportedFormats.filter(_.isEnabled(configuration.get[Configuration]("play.i18n.formats")))

/** map of supported loaders, mapping format name -> format loader */
def supportedFormats = List(
private def supportedFormats = List(
Format("properties", None, PropertyFileLoader),
Format("yaml", Some("yaml"), YamlFileLoader)
)

allFiles.map { file =>
private def messages: Map[String, Map[String, String]] = allFiles.map { file =>
file.key -> file.load
}.foldLeft(Map.empty[String, Map[String, String]]) {
case (merged, (lang, data)) if merged.contains(lang) =>
Expand All @@ -43,15 +38,19 @@ class MultiFormatMessagesApi @Inject()(implicit environment: Environment, config
case (merged, (key, data)) =>
merged + (key -> data)
}
}, langs = langs)

private val api = new DefaultMessagesApi(messages = messages, langs = langs)

override def get: MessagesApi = api
}

class MultiFormatMessagesModule extends Module {
def bindings(environment: Environment, configuration: Configuration) = {
def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] = {
Seq(
bind[Langs].toProvider[DefaultLangsProvider],
bind[MessagesApi].to[MultiFormatMessagesApi],
bind[MessagesApi].toProvider[MultiFormatMessagesApiProvider],
bind[play.i18n.MessagesApi].toSelf,
bind[play.i18n.Langs].toSelf
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import play.api.test._

class MultiFormatMessagingPluginSpec extends PlaySpecification {

val injector = new GuiceApplicationBuilder().injector
val injector = new GuiceApplicationBuilder().injector()

val messages = injector.instanceOf[MessagesApi]

Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "2.0.1-SNAPSHOT"
version in ThisBuild := "2.1.0-SNAPSHOT"

0 comments on commit 7c48402

Please sign in to comment.