lila/app/templating/NumberHelper.scala

25 lines
686 B
Scala
Raw Normal View History

2013-02-27 17:12:13 -07:00
package lila.app
2012-06-07 18:19:21 -06:00
package templating
import java.text.NumberFormat
2013-12-27 15:12:20 -07:00
import java.util.Locale
2012-06-07 18:19:21 -06:00
import scala.collection.mutable
2013-12-27 15:12:20 -07:00
import lila.user.UserContext
2012-06-07 18:19:21 -06:00
trait NumberHelper { self: I18nHelper
private val formatters = mutable.Map[String, NumberFormat]()
2014-02-06 11:22:28 -07:00
private def formatter(implicit ctx: UserContext): NumberFormat =
2012-06-07 18:19:21 -06:00
formatters.getOrElseUpdate(
lang(ctx).language,
NumberFormat getInstance new Locale(lang(ctx).language))
2014-02-06 11:22:28 -07:00
def showMillis(millis: Int)(implicit ctx: UserContext) = formatter format ((millis / 100).toDouble / 10)
2012-06-07 18:19:21 -06:00
implicit def richInt(number: Int) = new {
2014-02-06 11:22:28 -07:00
def localize(implicit ctx: UserContext): String = formatter format number
2012-06-07 18:19:21 -06:00
}
}