pluralization WIP

This commit is contained in:
Thibault Duplessis 2017-05-27 10:02:28 +02:00
parent 0f22e5a267
commit 4df8b64c2e
4 changed files with 62 additions and 52 deletions

View file

@ -1,5 +1,13 @@
package lila.i18n
import play.api.i18n.Lang
sealed trait Translation extends Any
case class Singular(message: String) extends AnyVal with Translation
case class Plurals(messages: Map[I18nQuantity, String]) extends AnyVal with Translation
object I18nDb {
val all: Messages =
@ -11,50 +19,50 @@ object I18nDb {
val langs = all.keySet
private def playDefaultMessages: Map[String, String] = Map(
"constraint.required" -> "Required",
"constraint.min" -> "Minimum value: {0}",
"constraint.max" -> "Maximum value: {0}",
"constraint.minLength" -> "Minimum length: {0}",
"constraint.maxLength" -> "Maximum length: {0}",
"constraint.email" -> "Email",
"format.date" -> "Date (''{0}'')",
"format.numeric" -> "Numeric",
"format.real" -> "Real",
"format.uuid" -> "UUID",
"error.invalid" -> "Invalid value",
"error.invalid.java.util.Date" -> "Invalid date value",
"error.required" -> "This field is required",
"error.number" -> "Numeric value expected",
"error.real" -> "Real number value expected",
"error.real.precision" -> "Real number value with no more than {0} digit(s) including {1} decimal(s) expected",
"error.min" -> "Must be greater or equal to {0}",
"error.min.strict" -> "Must be strictly greater than {0}",
"error.max" -> "Must be less or equal to {0}",
"error.max.strict" -> "Must be strictly less than {0}",
"error.minLength" -> "Minimum length is {0}",
"error.maxLength" -> "Maximum length is {0}",
"error.email" -> "Valid email required",
"error.pattern" -> "Must satisfy {0}",
"error.date" -> "Valid date required",
"error.uuid" -> "Valid UUID required",
"error.expected.date" -> "Date value expected",
"error.expected.date.isoformat" -> "Iso date value expected",
"error.expected.time" -> "Time value expected",
"error.expected.jodadate.format" -> "Joda date value expected",
"error.expected.jodatime.format" -> "Joda time value expected",
"error.expected.jsarray" -> "Array value expected",
"error.expected.jsboolean" -> "Boolean value expected",
"error.expected.jsnumber" -> "Number value expected",
"error.expected.jsobject" -> "Object value expected",
"error.expected.jsstring" -> "String value expected",
"error.expected.jsnumberorjsstring" -> "String or number expected",
"error.expected.keypathnode" -> "Node value expected",
"error.expected.uuid" -> "UUID value expected",
"error.expected.validenumvalue" -> "Valid enumeration value expected",
"error.expected.enumstring" -> "String value expected",
"error.path.empty" -> "Empty path",
"error.path.missing" -> "Missing path",
"error.path.result.multiple" -> "Multiple results for the given path"
private def playDefaultMessages: Map[MessageKey, Translation] = Map(
"constraint.required" -> Singular("Required"),
"constraint.min" -> Singular("Minimum value: {0}"),
"constraint.max" -> Singular("Maximum value: {0}"),
"constraint.minLength" -> Singular("Minimum length: {0}"),
"constraint.maxLength" -> Singular("Maximum length: {0}"),
"constraint.email" -> Singular("Email"),
"format.date" -> Singular("Date (''{0}'')"),
"format.numeric" -> Singular("Numeric"),
"format.real" -> Singular("Real"),
"format.uuid" -> Singular("UUID"),
"error.invalid" -> Singular("Invalid value"),
"error.invalid.java.util.Date" -> Singular("Invalid date value"),
"error.required" -> Singular("This field is required"),
"error.number" -> Singular("Numeric value expected"),
"error.real" -> Singular("Real number value expected"),
"error.real.precision" -> Singular("Real number value with no more than {0} digit(s) including {1} decimal(s) expected"),
"error.min" -> Singular("Must be greater or equal to {0}"),
"error.min.strict" -> Singular("Must be strictly greater than {0}"),
"error.max" -> Singular("Must be less or equal to {0}"),
"error.max.strict" -> Singular("Must be strictly less than {0}"),
"error.minLength" -> Singular("Minimum length is {0}"),
"error.maxLength" -> Singular("Maximum length is {0}"),
"error.email" -> Singular("Valid email required"),
"error.pattern" -> Singular("Must satisfy {0}"),
"error.date" -> Singular("Valid date required"),
"error.uuid" -> Singular("Valid UUID required"),
"error.expected.date" -> Singular("Date value expected"),
"error.expected.date.isoformat" -> Singular("Iso date value expected"),
"error.expected.time" -> Singular("Time value expected"),
"error.expected.jodadate.format" -> Singular("Joda date value expected"),
"error.expected.jodatime.format" -> Singular("Joda time value expected"),
"error.expected.jsarray" -> Singular("Array value expected"),
"error.expected.jsboolean" -> Singular("Boolean value expected"),
"error.expected.jsnumber" -> Singular("Number value expected"),
"error.expected.jsobject" -> Singular("Object value expected"),
"error.expected.jsstring" -> Singular("String value expected"),
"error.expected.jsnumberorjsstring" -> Singular("String or number expected"),
"error.expected.keypathnode" -> Singular("Node value expected"),
"error.expected.uuid" -> Singular("UUID value expected"),
"error.expected.validenumvalue" -> Singular("Valid enumeration value expected"),
"error.expected.enumstring" -> Singular("String value expected"),
"error.path.empty" -> Singular("Empty path"),
"error.path.missing" -> Singular("Missing path"),
"error.path.result.multiple" -> Singular("Multiple results for the given path")
)
}

View file

@ -4,7 +4,8 @@ import play.api.i18n.Lang
package object i18n extends PackageObject with WithPlay {
type Messages = Map[Lang, Map[String, String]]
type MessageKey = String
type Messages = Map[Lang, Map[MessageKey, Translation]]
private[i18n] def logger = lila.log("i18n")

View file

@ -322,7 +322,7 @@ object ApplicationBuild extends Build {
lazy val i18n = project("i18n", Seq(common, db, user, hub)).settings(
sourceGenerators in Compile += Def.task {
MessageCompiler(
sourceFile = new File("translation/source/site.csv"),
sourceFile = new File("translation/source/site.xml"),
destDir = new File("translation/dest/site"),
compileTo = (sourceManaged in Compile).value / "messages"
)

View file

@ -40,7 +40,7 @@ import play.api.i18n.Lang
// format: OFF
object Registry {
def load = Map[Lang, Map[String, String]]($content)
def load = Map[Lang, Map[MessageKey, Translation]]($content)
}
"""
}
@ -49,16 +49,17 @@ object Registry {
private def render(locale: String, pairs: List[(String, String)]) = {
def quote(msg: String) = s"""""\"$msg""\""""
val content = pairs.map {
case (key, message) => s""""$key"->${quote(message)}"""
} mkString ",\n"
// val content = pairs.map {
// case (key, message) => s""""$key"->${quote(message)}"""
// } mkString ",\n"
val content = ""
s"""package lila.i18n
package db
// format: OFF
private object `$locale` {
def load = Map[String, String]($content)
def load = Map[MessageKey, Translation]($content)
}
"""
}