Skip to content

Commit

Permalink
Migration to Play 2.9 (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: Karel Cemus <[email protected]>
  • Loading branch information
KarelCemus and Karel Cemus authored Nov 7, 2023
1 parent 4786031 commit 4fd8312
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 74 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build and Test
on:
pull_request:

push:
branches:
- master

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
build-and-test:
runs-on: ubuntu-22.04
timeout-minutes: 15
env:
SBT_OPTS: -Dfile.encoding=UTF-8 -Duser.timezone=UTC
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Cache Coursier
uses: coursier/[email protected]

- name: Setup JDK
uses: coursier/[email protected]
with:
jvm: adoptium:1.17

- name: Build
timeout-minutes: 10
run: |
sbt --client "+clean; +compile; +Test/compile; +test;"
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

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

**Note: This version supports Play framework 2.8.x. For compatibility with previous versions see previous releases.**
**Note: This version supports Play framework 2.9.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
an alternative to supporting YAML format for messages including all features of the language.

[![Build Status](https://travis-ci.org/KarelCemus/play-i18n.svg?branch=master)](https://travis-ci.org/KarelCemus/play-i18n)

## How to add the module into the project

To your SBT `build.sbt` add the following lines:

```scala
libraryDependencies ++= Seq(
// YAML localization module
"com.github.karelcemus" %% "play-i18n" % "2.3.0"
"com.github.karelcemus" %% "play-i18n" % "2.4.0"
)
```

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

organization := "com.github.karelcemus"

scalaVersion := "2.13.8"
scalaVersion := "2.13.12"

crossScalaVersions := Seq( scalaVersion.value, "2.12.15" )
crossScalaVersions := Seq(scalaVersion.value, "3.3.1")

val playVersion = "2.8.13"

val specs2Version = "4.13.2"
val playVersion = "2.9.0"

libraryDependencies ++= Seq(
// play framework cache API
"com.typesafe.play" %% "play" % playVersion % "provided",
// YAML parser, Java library
"org.yaml" % "snakeyaml" % "2.0",
"org.yaml" % "snakeyaml" % "2.2",
// test framework
"org.specs2" %% "specs2-core" % specs2Version % "test",
"org.specs2" %% "specs2-core" % "4.20.3" % "test",
// test module for play framework
"com.typesafe.play" %% "play-test" % playVersion % "test",
"com.typesafe.play" %% "play-specs2" % playVersion % "test"
)

resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"

javacOptions ++= Seq( "-source", "1.8", "-target", "1.8", "-Xlint:unchecked", "-encoding", "UTF-8" )
javacOptions ++= Seq("-Xlint:unchecked", "-encoding", "UTF-8")

scalacOptions ++= Seq( "-deprecation", "-feature", "-unchecked", "-Yrangepos" )
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-Yrangepos")

ThisBuild / versionScheme := Some("semver-spec")

homepage := Some( url( "https://github.com/karelcemus/play-i18n" ) )
homepage := Some(url("https://github.com/karelcemus/play-i18n"))

licenses := Seq( "Apache 2" -> url( "https://www.apache.org/licenses/LICENSE-2.0" ) )
licenses := Seq("Apache 2" -> url("https://www.apache.org/licenses/LICENSE-2.0"))

publishMavenStyle := true

Expand All @@ -57,11 +55,12 @@ pomExtra :=

// Release plugin settings
releaseCrossBuild := true
releaseTagName := ( ThisBuild / version ).value
releaseTagName := (ThisBuild / version).value
releasePublishArtifactsAction := PgpKeys.publishSigned.value

// Publish settings
publishTo := {
if ( isSnapshot.value ) Some( Opts.resolver.sonatypeSnapshots )
else Some( Opts.resolver.sonatypeStaging )
// Resolver.sonatypeOssRepos("snapshots")
if (isSnapshot.value) None
else Some(Opts.resolver.sonatypeStaging)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.6.1
sbt.version=1.9.7
2 changes: 1 addition & 1 deletion src/main/scala/play/ext/i18n/MessageFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import play.api._

protected[i18n] case class MessageFile(key: String, name: String, loader: MessagesLoader)(implicit configuration: Configuration, env: Environment) {

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

import play.api.i18n.Messages.UrlMessageSource
import play.utils.Resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import play.ext.i18n.MessagesLoader
class PropertyFileLoader extends MessagesLoader {

override def apply(messageSource: MessageSource, messageSourceName: String): Either[ExceptionSource, Map[String, String]] = {
new MessagesParser(messageSource, "").parse.right.map { messages =>
new MessagesParser(messageSource, "").parse.map { messages =>
messages.map { message => message.key -> message.pattern }.toMap
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/play/ext/i18n/loaders/YamlFileLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import play.ext.i18n.MessagesLoader
*/
class YamlFileLoader extends MessagesLoader {

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

private type JavaMap = java.util.Map[_, _]

Expand All @@ -25,8 +25,8 @@ class YamlFileLoader extends MessagesLoader {
// YAML document parser
val yaml = new Yaml()
// load data as a hierarchical map
val data = yaml.loadAs(messageSource.read, classOf[JavaMap])
val map = if (data == null) Map.empty[String, String] else flatten(data) // flatten the map
val data: Option[JavaMap] = Option(yaml.loadAs(messageSource.read, classOf[JavaMap]))
val map = data.map(flatten).getOrElse(Map.empty[String, String])
Right(map)
} catch {
case exception: ScannerException =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package play.ext.i18n

import play.api.i18n.MessagesApi
import play.api.i18n.{Lang, MessagesApi}
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test._

class MultiFormatMessagingPluginSpec extends PlaySpecification {

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

val messages = injector.instanceOf[MessagesApi]
private val messages = injector.instanceOf[MessagesApi]

implicit val default = play.api.i18n.Lang("fr")
private implicit val default: Lang = play.api.i18n.Lang("fr")

val cs = play.api.i18n.Lang("cs")
private val cs = play.api.i18n.Lang("cs")

val en = play.api.i18n.Lang("en")
private val en = play.api.i18n.Lang("en")

"Plugin" should {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.ext.i18n.loaders

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

import play.api.i18n.Messages.{MessageSource, UrlMessageSource}

Expand Down

0 comments on commit 4fd8312

Please sign in to comment.