Access translated i18n messages from Scala templates (Play! Internationalization)

孤街浪徒 提交于 2019-12-04 15:29:56

In your scala file use:

<h1>@Messages("pack.key")</h1>

And in your java file use :

String title = Messages.get("pack.key");

Don't forget to add quote around your language list : conf/application.conf

application.langs="en-GB,de-DE,nl-NL"

Changing the language is not possible in Play! 2.0, see this discussion: http://groups.google.com/group/play-framework/browse_thread/thread/744d523c169333ac/5bfe28732a6efd89?show_docid=5bfe28732a6efd89

and this ticket: https://play.lighthouseapp.com/projects/82401-play-20/tickets/174-20-i18n-add-ability-to-define-implicit-lang-for-java-api#ticket-174-4

Although, when you register multiple languages you should enclose them in double qoutes, like this:

application.langs="en-GB,de-DE,nl-NL"

And then you can access them from the scala templates like this:

@Messages.get("login.title")

So currently the default language is the language that is defined in the file messages (without any prefix!!)

Or you can just use @Messages("not.logged.in")

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