Java Playframework Internationalization doesn't work

五迷三道 提交于 2019-12-08 06:33:19

问题


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

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?


回答1:


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.




回答2:


In my specific case I had

play.http.session.domain

set to something else other than localhost while testing.



来源:https://stackoverflow.com/questions/6314855/java-playframework-internationalization-doesnt-work

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