<commit_before>package lila.app
package templating

import controllers._
import lila.user.Context
import lila.i18n.Env.{ current => i18nEnv }
import lila.i18n.{ LangList, I18nDomain }

import play.api.i18n.Lang
import play.api.templates.Html
import play.api.mvc.{ RequestHeader, Call }
import scala.util.Random.shuffle

trait I18nHelper {

  private def pool = i18nEnv.pool
  private def transInfos = i18nEnv.transInfos
  private def hideCallsCookieName = i18nEnv.hideCallsCookieName

  lazy val trans = i18nEnv.keys
  lazy val protocol = i18nEnv.RequestHandlerProtocol

  implicit def lang(implicit ctx: Context) = pool lang ctx.req

  def langName(lang: Lang) = LangList name lang.language

  def translationCall(implicit ctx: Context) =
    if (ctx.req.cookies.get(hideCallsCookieName).isDefined) None
    else shuffle(
      (ctx.req.acceptLanguages map transInfos.get).flatten filter (_.nonComplete)
    ).headOption

  def transValidationPattern(trans: String) =
    (trans contains "%s") option ".*%s.*"

  private lazy val otherLangLinksCache =
    scala.collection.mutable.Map[String, String]()

  def otherLangLinks(lang: Lang)(implicit ctx: Context) = Html {
    otherLangLinksCache.getOrElseUpdate(lang.language, {
      pool.names.toList sortBy (_._1) collect {
        case (code, name) if code != lang.language ⇒
          """<li><a lang="%s" href="%s">%s</a></li>"""
            .format(code, langUrl(Lang(code))(ctx.req), name)
      } mkString
    }).replace(uriPlaceholder, ctx.req.uri)
  }

  def commonDomain(implicit ctx: Context): String =
    I18nDomain(ctx.req.domain).commonDomain

  val uriPlaceholder = "[URI]"

  private def langUrl(lang: Lang)(req: RequestHeader) =
    protocol + (I18nDomain(req.domain) withLang lang).domain + uriPlaceholder
}<commit_msg>instanciate less objects to generate lang list<commit_after>package lila.app
package templating

import controllers._
import lila.user.Context
import lila.i18n.Env.{ current => i18nEnv }
import lila.i18n.{ LangList, I18nDomain }

import play.api.i18n.Lang
import play.api.templates.Html
import play.api.mvc.{ RequestHeader, Call }
import scala.util.Random.shuffle

trait I18nHelper {

  private def pool = i18nEnv.pool
  private def transInfos = i18nEnv.transInfos
  private def hideCallsCookieName = i18nEnv.hideCallsCookieName

  lazy val trans = i18nEnv.keys
  lazy val protocol = i18nEnv.RequestHandlerProtocol

  implicit def lang(implicit ctx: Context) = pool lang ctx.req

  def langName(lang: Lang) = LangList name lang.language

  def translationCall(implicit ctx: Context) =
    if (ctx.req.cookies.get(hideCallsCookieName).isDefined) None
    else shuffle(
      (ctx.req.acceptLanguages map transInfos.get).flatten filter (_.nonComplete)
    ).headOption

  def transValidationPattern(trans: String) =
    (trans contains "%s") option ".*%s.*"

  private lazy val otherLangLinksCache =
    scala.collection.mutable.Map[String, String]()

  def otherLangLinks(lang: Lang)(implicit ctx: Context) = Html {
    otherLangLinksCache.getOrElseUpdate(lang.language, {
      val i18nDomain = I18nDomain(ctx.req.domain)
      pool.names.toList sortBy (_._1) collect {
        case (code, name) if code != lang.language ⇒
          """<li><a lang="%s" href="%s">%s</a></li>"""
            .format(code, langUrl(Lang(code))(i18nDomain), name)
      } mkString
    }).replace(uriPlaceholder, ctx.req.uri)
  }

  def commonDomain(implicit ctx: Context): String =
    I18nDomain(ctx.req.domain).commonDomain

  val uriPlaceholder = "[URI]"

  private def langUrl(lang: Lang)(i18nDomain: I18nDomain) =    
    protocol + (i18nDomain withLang lang).domain + uriPlaceholder
}
{'fraction_non_alphanumeric': 0.11405908096280087, 'fraction_numerical': 0.0175054704595186, 'mean_word_length': 4.030261348005502, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2245252', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1192, 'n_words': 283}