also compile english translations
This commit is contained in:
parent
760f1a9134
commit
ac06109069
|
@ -321,8 +321,9 @@ object ApplicationBuild extends Build {
|
||||||
lazy val i18n = project("i18n", Seq(common, db, user, hub)).settings(
|
lazy val i18n = project("i18n", Seq(common, db, user, hub)).settings(
|
||||||
sourceGenerators in Compile += Def.task {
|
sourceGenerators in Compile += Def.task {
|
||||||
MessageCompiler(
|
MessageCompiler(
|
||||||
new File("translation/dest/site"),
|
sourceFile = new File("translation/source/site.csv"),
|
||||||
(sourceManaged in Compile).value / "messages"
|
destDir = new File("translation/dest/site"),
|
||||||
|
compileTo = (sourceManaged in Compile).value / "messages"
|
||||||
)
|
)
|
||||||
}.taskValue,
|
}.taskValue,
|
||||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||||
|
|
|
@ -4,32 +4,30 @@ import sbt._, Keys._
|
||||||
|
|
||||||
object MessageCompiler {
|
object MessageCompiler {
|
||||||
|
|
||||||
def apply(src: File, dst: File): Seq[File] = {
|
def apply(sourceFile: File, destDir: File, compileTo: File): Seq[File] = {
|
||||||
val startsAt = System.currentTimeMillis()
|
val startsAt = System.currentTimeMillis()
|
||||||
val sourceFiles = Option(src.list) getOrElse Array() filter (_ endsWith ".csv")
|
val registry = ("en-EN" -> sourceFile) :: destDir.list.toList.map { f =>
|
||||||
val registry = sourceFiles.toList.map { f =>
|
f.takeWhile('.' !=) -> (destDir / f)
|
||||||
f.takeWhile('.' !=) -> f
|
|
||||||
}
|
}
|
||||||
dst.mkdirs()
|
compileTo.mkdirs()
|
||||||
val registryFile = writeRegistry(dst, registry)
|
val registryFile = writeRegistry(compileTo, registry)
|
||||||
val res = for (entry <- registry) yield {
|
val res = for (entry <- registry) yield {
|
||||||
val (locale, file) = entry
|
val (locale, file) = entry
|
||||||
val srcFile = src / file
|
val compileToFile = compileTo / s"$locale.scala"
|
||||||
val dstFile = dst / s"$locale.scala"
|
if (file.lastModified > compileToFile.lastModified) {
|
||||||
if (srcFile.lastModified > dstFile.lastModified) {
|
val pairs = readLines(file) flatMap makePair
|
||||||
val pairs = readLines(srcFile) flatMap makePair
|
printToFile(compileToFile) {
|
||||||
printToFile(dstFile) {
|
|
||||||
render(locale, pairs)
|
render(locale, pairs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dstFile
|
compileToFile
|
||||||
}
|
}
|
||||||
println(s"MessageCompiler took ${System.currentTimeMillis() - startsAt}ms")
|
println(s"MessageCompiler took ${System.currentTimeMillis() - startsAt}ms")
|
||||||
registryFile :: res
|
registryFile :: res
|
||||||
}
|
}
|
||||||
|
|
||||||
private def writeRegistry(dst: File, registry: List[(String, String)]) = {
|
private def writeRegistry(compileTo: File, registry: List[(String, File)]) = {
|
||||||
val file = dst / "Registry.scala"
|
val file = compileTo / "Registry.scala"
|
||||||
printToFile(file) {
|
printToFile(file) {
|
||||||
val content = registry.map {
|
val content = registry.map {
|
||||||
case (locale, _) => s""""$locale"->`$locale`.load"""
|
case (locale, _) => s""""$locale"->`$locale`.load"""
|
||||||
|
|
Loading…
Reference in a new issue