scala - Change language of text in template in play framework 2.1.1 -


i want user of application can change language in play2 (play 2.1.1, scala 2.10.1) web application. use @messages.get(...) in templates i18n.

i have

application.langs="en,ru" 

in application.conf. pass "en" or "ru" method:

def index = action {    ok(views.html.index()) }  def changelanguage(lang:string) = action {   implicit request =>     logger.logger.debug("change user lang : " + lang)     val referrer = request.headers.get(referer).getorelse(home_url)     redirect(referrer).withlang(lang(lang)) } 

routes:

get     /                           controllers.application.index     /index                      controllers.application.changelanguage(lang ?= "ru") 

the template bunch (views.html.index):

@()(implicit l: lang)  @import play.i18n.messages  ...  <a href="/about">@messages.get("about")</li>  ...  <a href="index?lang=ru" id="ru"></a> <a href="index?lang=en" id="en"></a> ... 

after redirecting page, see on same language. :(

i read many old answers: implicit language parameter in template not work, redirect or action withlang(...) method call too. did not have solution long time?

i made work, there changes. in app code (without request instance play not know cookie language?):

def index = action {  implicit request=>    ok(views.html.index()) } 

and in template (play.api.i18n imports automatically):

@()(implicit l: lang)  ...  <a href="/about">@messages("about")</li>  ...  <a href="index?lang=ru" id="ru"></a> <a href="index?lang=en" id="en"></a> ... 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -