improve translation fetch
This commit is contained in:
parent
ca3e8e6868
commit
40ee27169d
|
@ -3,8 +3,8 @@ package lila.api
|
|||
private[api] final class Cli(env: Env) {
|
||||
|
||||
def apply(args: List[String]): Fu[String] = run(args).map(_ + "\n") ~ {
|
||||
_ logFailure("[cli] " + args.mkString(" ")) foreach {
|
||||
case output ⇒ loginfo("[cli] %s\n%s".format(args mkString " ", output))
|
||||
_ logFailure ("[cli] " + args.mkString(" ")) foreach { output ⇒
|
||||
loginfo("[cli] %s\n%s".format(args mkString " ", output))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,14 +11,12 @@ private[i18n] final class GitWrite(transRelPath: String, repoPath: String) {
|
|||
private val repo = new FileRepository(repoPath + "/.git")
|
||||
private val git = new Git(repo, debug = true)
|
||||
|
||||
private def putStrLn(msg: String) = fuccess(println(msg))
|
||||
|
||||
def apply(translations: List[Translation]): Funit = for {
|
||||
_ ← putStrLn("Working on " + repoPath)
|
||||
_ ← fuloginfo("Working on " + repoPath)
|
||||
currentBranch ← git.currentBranch
|
||||
_ ← putStrLn("Current branch is " + currentBranch)
|
||||
_ ← (translations map write).sequence.void
|
||||
_ ← putStrLn("Checkout " + currentBranch)
|
||||
_ ← fuloginfo("Current branch is " + currentBranch)
|
||||
_ ← (translations.pp map write).sequence.void
|
||||
_ ← fuloginfo("Checkout " + currentBranch)
|
||||
_ ← git checkout currentBranch
|
||||
} yield ()
|
||||
|
||||
|
@ -29,19 +27,19 @@ private[i18n] final class GitWrite(transRelPath: String, repoPath: String) {
|
|||
val commitMsg = commitMessage(translation, name)
|
||||
git branchExists branch flatMap {
|
||||
_.fold(
|
||||
putStrLn("! Branch already exists: " + branch) >>
|
||||
fuloginfo("! Branch already exists: " + branch) >>
|
||||
git.checkout(branch, true) >>
|
||||
writeMessages(translation) >>
|
||||
putStrLn("Add " + relFileOf(translation)) >>
|
||||
fuloginfo("Add " + relFileOf(translation)) >>
|
||||
(git add relFileOf(translation)) >>
|
||||
putStrLn("- " + commitMsg) >>
|
||||
fuloginfo("- " + commitMsg) >>
|
||||
(git commit commitMsg).void,
|
||||
funit)
|
||||
}
|
||||
}
|
||||
|
||||
private def writeMessages(translation: Translation) =
|
||||
putStrLn("Write messages to " + absFileOf(translation)) >>
|
||||
fuloginfo("Write messages to " + absFileOf(translation)) >>
|
||||
printToFile(absFileOf(translation)) { writer ⇒
|
||||
translation.lines foreach writer.println
|
||||
}
|
||||
|
@ -92,7 +90,7 @@ private[i18n] final class GitWrite(transRelPath: String, repoPath: String) {
|
|||
private def cleanupBranch(branch: String) =
|
||||
branch.replace("refs/heads/", "")
|
||||
|
||||
private def log(msg: ⇒ Any) = debug.fold(putStrLn(msg.toString), funit)
|
||||
private def log(msg: ⇒ Any) = debug.fold(fuloginfo(msg.toString), funit)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ private[i18n] case class Translation(
|
|||
createdAt: DateTime) {
|
||||
|
||||
def lines = text.split("\n").toList
|
||||
|
||||
override def toString = "#%d %s".format(id, code)
|
||||
}
|
||||
|
||||
private[i18n] object Translation {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lila.i18n
|
||||
|
||||
import lila.common.PimpedJson._
|
||||
import tube.translationTube
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.ws.WS
|
||||
|
@ -12,35 +13,16 @@ private[i18n] final class UpstreamFetch(upstreamUrl: Int ⇒ String) {
|
|||
private type Fetched = Fu[List[Translation]]
|
||||
|
||||
def apply(from: Int): Fetched =
|
||||
fetch(upstreamUrl(from)) map parse
|
||||
fetch(upstreamUrl(from)) map parse flatMap {
|
||||
_.fold(e ⇒ fufail(e.toString), fuccess(_))
|
||||
}
|
||||
|
||||
def apply(from: String): Fetched =
|
||||
parseIntOption(from).fold(fufail("Bad from argument"): Fetched)(apply)
|
||||
|
||||
// private def upstreamUrl(from: Int) =
|
||||
// "http://" + upstreamDomain + routes.I18n.fetch(from)
|
||||
|
||||
private def fetch(url: String): Fu[JsValue] =
|
||||
WS.url(url).get() map (_.json)
|
||||
|
||||
// this function signature is lying.
|
||||
private def parse(json: JsValue): List[Translation] =
|
||||
(json.as[List[JsObject]].value map parseTranslation).toList map {
|
||||
_ err "Received broken JSON from upstream"
|
||||
}
|
||||
|
||||
private def parseTranslation(js: JsObject): Option[Translation] = for {
|
||||
id ← js int "id"
|
||||
code ← js str "code"
|
||||
text ← js str "text"
|
||||
author = js str "author"
|
||||
comment = js str "comment"
|
||||
ts ← js long "createdAt"
|
||||
} yield Translation(
|
||||
id = id,
|
||||
code = code,
|
||||
text = text,
|
||||
author = author,
|
||||
comment = comment,
|
||||
createdAt = new DateTime(ts))
|
||||
private def parse(json: JsValue): JsResult[List[Translation]] =
|
||||
Json.fromJson[List[Translation]](json)
|
||||
}
|
||||
|
|
1
todo
1
todo
|
@ -49,7 +49,6 @@ opponent history http://imgur.com/ur1Mt http://en.lichess.org/forum/lichess-feed
|
|||
show tournament trophies on user profile
|
||||
mute ip
|
||||
games with me http://en.lichess.org/forum/general-chess-discussion/-vs-me#2
|
||||
ssl websocket would pass through proxies http://en.lichess.org/forum/lichess-feedback/layout-bug-and-proxies#2 requires play 2.1
|
||||
team chat
|
||||
let players block other players
|
||||
detect lack of support for date formatting (gl) and use 2013-02-15 13:48:00 instead
|
||||
|
|
Loading…
Reference in a new issue