从Scala模板访问翻译的i18n消息(播放!国际化)
在我的游戏中! 2.0应用程序我想定义以下语言:
In my Play! 2.0 application I would like to define the following languages:
# The application languages
# ~~~~~
application.langs=en-GB,de-DE,nl-NL
我还创建了3个以相应语言代码结尾的文件:
I also have created 3 files that ends with the corresponding language codes:
Messages.en-GB
Messages.de-DE
Messages.nl-NL
当我在没有任何要求翻译密钥的情况下启动应用程序时,出现以下错误消息:
When I start the application without any request for a translated key I get the following error message:
conf/application.conf: 12: Key 'de-DE' may not be followed by token: ',' (if you intended ',' to be part of the value for 'de-DE', try enclosing the value in double quotes)
当尝试从Scala模板访问消息时,我仍然看到相同的消息.我通过以下代码请求消息:
Also when trying to access a message from the Scala template I still see the same message. I request the message by the following code:
@Messages("login.page")
我根据Play手册进行了上述更改: http://www.playframework. org/documentation/2.0/JavaI18N .所以我有两个问题:
The above changes I have done according to the Play manual: http://www.playframework.org/documentation/2.0/JavaI18N . So I have two questions:
- 如何设置默认语言并像1.2.4(Lang.change("en-GB"))一样更改语言
- 如何从Scala模板访问消息?
在Play中无法更改语言! 2.0,请参见以下讨论: http://groups .google.com/group/play-framework/browse_thread/thread/744d523c169333ac/5bfe28732a6efd89?show_docid = 5bfe28732a6efd89
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
和此票证:尽管,当您注册多种语言时,应将它们用双qoutes括起来,如下所示:
Although, when you register multiple languages you should enclose them in double qoutes, like this:
application.langs="en-GB,de-DE,nl-NL"
然后您可以像下面这样从scala模板访问它们:
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!!)
或者您可以只使用@Messages("not.logged.in")
Or you can just use @Messages("not.logged.in")