Change language of text in template in play framework 2.1.1

ぐ巨炮叔叔 提交于 2019-12-06 13:01:44

I made it work, so there are my changes. In app code (without an request instance play does not know where to get the cookie with the language?):

def index = Action {
 implicit request=>
   Ok(views.html.index())
}

And in the 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>
...

I had the same issue and added my own message-resolution class over the play.i18n one.

For message resolution, you can have a example here (in Java): https://github.com/adericbourg/proto-poll/blob/dev/app/util/user/message/Messages.java#L76

And my controller changeLang's method calls this: https://github.com/adericbourg/proto-poll/blob/dev/app/util/security/CurrentUser.java#L71

It do not believe it is a good solution (it requires more code and I'm a lazy guy) but it works. Hope this can help...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!