Java Playframework国际化无效 [英] Java Playframework Internationalization doesn't work

查看:141
本文介绍了Java Playframework国际化无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了这里的说明: http://www.playframework.org/documentation/1.2.1/i18n

I used the instructions from here: http://www.playframework.org/documentation/1.2.1/i18n

并创建了不同语言的文件.

and created files for different languages.

我调用play.i18n.Lang.change方法来更改语言文件, 并且仍从英文文件中获取标题("messages"(不带后缀))

I call play.i18n.Lang.change method to change the language file, and it still takes the captions from the English file ("messages" without a suffix),

有什么想法吗?

推荐答案

很难从您的描述中确切知道问题可能出在哪里,所以我概述了您应该如何使用多语言应用程序.

It is hard to know from your description exactly what the problem may be, so I have outlined how you should do a multi-lingual app.

要使国际化生效,您必须执行许多步骤.首先,必须更改application.conf文件以声明支持的语言.

There are a number of steps you must follow to get internationalisation to work. Firstly, you must change your application.conf file to declare your supported languages.

因此,如果您支持英语和法语,则可以

So, if you are supporting English and French, you would do

application.langs=en,fr

然后必须为法语翻译创建名为messages.fr的语言文件.英文只会保留在标准messages文件中.在这个新文件中,为密钥和消息添加名称/值对.

You must then create the language file for your French translation called messages.fr. The English language would just stay in the standard messages file. In this new file, add your name value pairs for the key and message.

Play处理消息的方式是先在特定于区域设置的消息文件中查找(因此对于英语来说,它是messages.en,它不存在,对于法语,它是messages.fr).如果在区域设置特定的消息文件中找不到该消息,它将查看全局消息文件.因此,您的全局messages文件可作为全部捕获文件.

The way Play processes the messages, is to look first in the locale specific message file first (so for english it would be messages.en, which does not exist, and for french it would be messages.fr). If the message cannot be found in the locale specific message file, it will look at the global message file. So your global messages file acts as the catch all.

然后,在您的代码中,使用

Then, in your code, set the language for your particular user, using

Lang.change("fr"); // change language to French

请记住,这会将特定用户的cookie保存在PLAY_LANG cookie中,因此请检查是否正在为该用户创建该cookie.

Remember, that this will save a cookie for the particular user in a PLAY_LANG cookie, so check that this cookie is being created for the user.

最后一点,请确保您的文件是UTF8编码的.如果不是这样,就会引起问题.

Final note, make sure that your files are UTF8 encoded. It causes problems if it is not.

这篇关于Java Playframework国际化无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆