Issue with selecting preferred language


(Chong Lee Zhen) #1

I’m using Play version 2.6.17

In application.conf, I set play.i18n.langs = [ “zh”, “en” ]
Accept languages in request I received from browser is [ “en-US” ].
However, the website is display in Chinese instead of English.

I did some debugging and found out that preferred method in play.api.i18n.Langs returns None instead of en.

Here some test cases that I did for this issue,

import play.api.i18n.{Lang, Langs}
import play.api.test.{Helpers, PlaySpecification}

class LangsSpec extends PlaySpecification {

“preferred method in play.api.i18n.Langs” should {
val availables: Seq[Lang] = Seq(Lang(“zh”), Lang(“zh-CN”), Lang(“en”))
val langs: Langs = Helpers.stubLangs(availables)

"return en if accept language is en-US" in {
  val acceptLanguages: Seq[Lang] = Seq(Lang("en-US"))
  langs.preferred(acceptLanguages) mustEqual Lang("en")
}

"return zh-CN if accept language is zh-CN" in {
  val acceptLanguages: Seq[Lang] = Seq(Lang("zh-CN"))
  langs.preferred(acceptLanguages) mustEqual Lang("zh-CN")
}

}
}

“return en if accept language is en-US” failed
“return zh-CN if accept language is zh-CN” success

Is there some settings that I missed for proper i18n support in Play framework?