java play framework,Java Playframework国际化无效

and created files for different languages.

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),

Any ideas why?

解决方案

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.

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

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.

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

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值