Skip to content

Instantly share code, notes, and snippets.

@teenasharma
Created July 14, 2017 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teenasharma/6da19d3b6685544ce41d877b714907c7 to your computer and use it in GitHub Desktop.
Save teenasharma/6da19d3b6685544ce41d877b714907c7 to your computer and use it in GitHub Desktop.
class MySupportController @Inject()(component: ControllerComponents,
langs: Langs) extends AbstractController(component) with I18nSupport {
val lang: Lang = langs.availables.head
implicit val messages: Messages = MessagesImpl(lang, messagesApi)
def index = Action { implicit request =>
val messages: Messages = messagesApi.preferred(request) // get the messages for the given request
val message: String = messages("default.message")
Ok(views.html.index(message))
}
def homePageInFrench = Action {
Redirect("/").withLang(Lang("fr")) // set french language in the Play's language cookie for future requests
}
def homePageWithDefaultLang = Action {
Redirect("/").clearingLang // discarding the language cookie set by withLang
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment