ensure that all Q&A texts are written in english
This commit is contained in:
parent
4571b7613e
commit
647633cd47
|
@ -15,4 +15,3 @@
|
|||
<div class="tags_list"></div>
|
||||
</div>
|
||||
@base.captcha(form("move"), form("gameId"), captcha)
|
||||
@errMsg(form)
|
||||
|
|
|
@ -2,13 +2,18 @@ package lila.qa
|
|||
|
||||
import play.api.data._
|
||||
import play.api.data.Forms._
|
||||
import play.api.i18n.Lang
|
||||
|
||||
private[qa] final class DataForm(val captcher: akka.actor.ActorSelection) extends lila.hub.CaptchedForm {
|
||||
private[qa] final class DataForm(
|
||||
val captcher: akka.actor.ActorSelection,
|
||||
detectLanguage: lila.common.DetectLanguage) extends lila.hub.CaptchedForm {
|
||||
|
||||
lazy val question = Form(
|
||||
mapping(
|
||||
"title" -> nonEmptyText(minLength = 10, maxLength = 150),
|
||||
"body" -> nonEmptyText(minLength = 10, maxLength = 10000),
|
||||
"title" -> nonEmptyText(minLength = 10, maxLength = 150)
|
||||
.verifying(languageMessage, validateLanguage _),
|
||||
"body" -> nonEmptyText(minLength = 10, maxLength = 10000)
|
||||
.verifying(languageMessage, validateLanguage _),
|
||||
"hidden-tags" -> text,
|
||||
"gameId" -> text,
|
||||
"move" -> text
|
||||
|
@ -24,7 +29,8 @@ private[qa] final class DataForm(val captcher: akka.actor.ActorSelection) extend
|
|||
|
||||
lazy val answer = Form(
|
||||
mapping(
|
||||
"body" -> nonEmptyText(minLength = 30),
|
||||
"body" -> nonEmptyText(minLength = 30)
|
||||
.verifying(languageMessage, validateLanguage _),
|
||||
"gameId" -> text,
|
||||
"move" -> text
|
||||
)(AnswerData.apply)(AnswerData.unapply)
|
||||
|
@ -33,17 +39,24 @@ private[qa] final class DataForm(val captcher: akka.actor.ActorSelection) extend
|
|||
lazy val editAnswer = Form(
|
||||
single(
|
||||
"body" -> nonEmptyText(minLength = 30)
|
||||
.verifying(languageMessage, validateLanguage _)
|
||||
))
|
||||
|
||||
lazy val comment = Form(
|
||||
mapping(
|
||||
"body" -> nonEmptyText(minLength = 20)
|
||||
.verifying(languageMessage, validateLanguage _)
|
||||
)(CommentData.apply)(CommentData.unapply)
|
||||
)
|
||||
|
||||
val vote = Form(single(
|
||||
"vote" -> number
|
||||
))
|
||||
|
||||
private val languageMessage = "I didn't understand that. Is it written in english?"
|
||||
|
||||
private def validateLanguage(str: String) =
|
||||
detectLanguage(str).await.??(_ == Lang("en"))
|
||||
}
|
||||
|
||||
private[qa] case class QuestionData(
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package lila.qa
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import lila.common.DetectLanguage
|
||||
import lila.common.PimpedConfig._
|
||||
|
||||
final class Env(
|
||||
config: Config,
|
||||
hub: lila.hub.Env,
|
||||
detectLanguage: DetectLanguage,
|
||||
db: lila.db.Env) {
|
||||
|
||||
private val CollectionQuestion = config getString "collection.question"
|
||||
|
@ -26,7 +28,7 @@ final class Env(
|
|||
|
||||
lazy val search = new Search(questionColl)
|
||||
|
||||
lazy val forms = new DataForm(hub.actor.captcher)
|
||||
lazy val forms = new DataForm(hub.actor.captcher, detectLanguage)
|
||||
}
|
||||
|
||||
object Env {
|
||||
|
@ -34,5 +36,6 @@ object Env {
|
|||
lazy val current = "[boot] qa" describes new Env(
|
||||
config = lila.common.PlayApp loadConfig "qa",
|
||||
hub = lila.hub.Env.current,
|
||||
detectLanguage = DetectLanguage(lila.common.PlayApp loadConfig "detectlanguage"),
|
||||
db = lila.db.Env.current)
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@ import lila.common.paginator._
|
|||
import lila.db.BSON.BSONJodaDateTimeHandler
|
||||
import lila.db.paginator._
|
||||
import lila.db.Types.Coll
|
||||
import lila.user.{ User, UserRepo }
|
||||
import lila.memo.AsyncCache
|
||||
import lila.user.{ User, UserRepo }
|
||||
|
||||
final class QaApi(questionColl: Coll, answerColl: Coll, notifier: Notifier) {
|
||||
final class QaApi(
|
||||
questionColl: Coll,
|
||||
answerColl: Coll,
|
||||
notifier: Notifier) {
|
||||
|
||||
object question {
|
||||
|
||||
|
|
Loading…
Reference in a new issue