Created
July 14, 2017 10:11
-
-
Save teenasharma/6da19d3b6685544ce41d877b714907c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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