more i18n rewrite

crowdin-no-subdomain
Thibault Duplessis 2017-05-26 19:16:30 +02:00
parent 9171b27eab
commit 4085ac6c0f
7 changed files with 37 additions and 36 deletions

View File

@ -39,7 +39,7 @@ object Dasher extends LilaController {
"user" -> ctx.me.map(_.light),
"lang" -> Json.obj(
"current" -> ctx.lang.code,
"accepted" -> (ctx.req.acceptLanguages.map(_.code)(breakOut): List[String]).distinct
"accepted" -> lila.i18n.I18nLangPicker.allFromRequestHeaders(ctx.req).map(_.code)
),
"sound" -> Json.obj(
"list" -> lila.pref.SoundSet.list.map { set =>

View File

@ -10,8 +10,10 @@ import lila.common.{ LilaCookie, HTTPRequest }
object I18n extends LilaController {
private def toLang = lila.i18n.I18nLangPicker.byStr _
private val form = Form(single("lang" -> text.verifying { code =>
Lang.get(code) ?? lila.i18n.I18nDb.langs.contains
toLang(code).isDefined
}))
def select = OpenBody { implicit ctx =>
@ -19,14 +21,12 @@ object I18n extends LilaController {
form.bindFromRequest.fold(
_ => notFound,
code => {
val lang = Lang(code)
ctx.me.filterNot(_.lang contains lang.code) ?? { me =>
val lang = toLang(code) err "Universe is collapsing"
ctx.me.filterNot(_.lang contains lang.code).?? { me =>
lila.user.UserRepo.setLang(me.id, lang.code)
}
} >> negotiate(
html = {
val redir = Redirect {
s"${Env.api.Net.Protocol}${lang}.${Env.api.Net.Domain}" + {
} >> negotiate(
html = {
val redir = Redirect {
HTTPRequest.referer(ctx.req).fold(routes.Lobby.home.url) { str =>
try {
val pageUrl = new java.net.URL(str);
@ -39,12 +39,12 @@ object I18n extends LilaController {
}
}
}
}
if (ctx.isAnon) redir.withCookies(LilaCookie.session("lang", lang.code))
else redir
}.fuccess,
api = _ => Ok(Json.obj("lang" -> lang.code)).fuccess
)
if (ctx.isAnon) redir.withCookies(LilaCookie.session("lang", lang.code))
else redir
}.fuccess,
api = _ => Ok(Json.obj("lang" -> lang.code)).fuccess
)
}
)
}
}

View File

@ -3,4 +3,4 @@
COMMAND=$*
PASSWORD=$LILA_CLI_PASSWORD
curl -d "password=$PASSWORD&command=$COMMAND" http://en.l.org/cli
curl -d "password=$PASSWORD&command=$COMMAND" http://l.org/cli

View File

@ -3,4 +3,4 @@
COMMAND=$*
PASSWORD=$LILA_CLI_PASSWORD
curl -d "password=$PASSWORD&command=$COMMAND" http://en.lichess.org/cli
curl -d "password=$PASSWORD&command=$COMMAND" http://lichess.org/cli

View File

@ -13,15 +13,18 @@ object I18nLangPicker {
.orElse(req.session get "lang")
.flatMap(Lang.get)
.flatMap(findCloser)
.orElse(fromRequestHeaders(req))
.orElse(bestFromRequestHeaders(req))
.getOrElse(defaultLang)
private def fromRequestHeaders(req: RequestHeader): Option[Lang] =
private def bestFromRequestHeaders(req: RequestHeader): Option[Lang] =
req.acceptLanguages.foldLeft(none[Lang]) {
case (None, lang) => findCloser(lang)
case (found, _) => found
}
def allFromRequestHeaders(req: RequestHeader): List[Lang] =
req.acceptLanguages.flatMap(findCloser).distinct.toList
def byStr(str: String): Option[Lang] =
Lang get str flatMap findCloser

View File

@ -33,25 +33,23 @@ private[i18n] final class JsDump(path: String) {
""""%s":"%s"""".format(key, escape(Translator.str(key, Nil, lang)))
}.mkString("{", ",", "}")
private def writeRefs {
val code = LangList.all.toList.sortBy(_._1.toString).map {
case (code, name) => s"""["$code","$name"]"""
private def writeRefs = writeFile(
new File("%s/refs.json".format(pathFile.getCanonicalPath)),
LangList.all.toList.sortBy(_._1.code).map {
case (lang, name) => s"""["${lang.code}","$name"]"""
}.mkString("[", ",", "]")
val file = new File("%s/refs.json".format(pathFile.getCanonicalPath))
val out = new PrintWriter(file)
try { out.print(code) }
finally { out.close }
)
private def writeFullJson = I18nDb.langs foreach { lang =>
val code = dumpFromKey(I18nDb.all(defaultLang).keys, lang)
val file = new File("%s/%s.all.json".format(pathFile.getCanonicalPath, lang.language))
writeFile(new File("%s/%s.all.json".format(pathFile.getCanonicalPath, lang.language)), code)
}
private def writeFullJson {
val keys = I18nDb.all(defaultLang).keys
I18nDb.langs foreach { lang =>
val code = dumpFromKey(keys, lang)
val file = new File("%s/%s.all.json".format(pathFile.getCanonicalPath, lang.language))
val out = new PrintWriter(file)
try { out.print(code) }
finally { out.close }
}
private def writeFile(file: File, content: String) = {
val out = new PrintWriter(file)
try { out.print(content) }
finally { out.close }
}
private def escape(text: String) = text.replace(""""""", """\"""")

View File

@ -280,7 +280,7 @@ lichess.StrongSocket.defaults = {
autoReconnectDelay: 2000,
protocol: location.protocol === 'https:' ? 'wss:' : 'ws:',
baseUrls: (function(domain) {
var main = 'socket.' + domain.split('.').slice(1).join('.');
var main = 'socket.' + domain;
var isProduction = /lichess\.org/.test(main);
var extraPorts = [];
if (isProduction) {