0

I added messages.en and messages.fi files to conf folder (deleted original messages file). Then I added En and Fi buttons together with a router call, which call following Action in my controller.

public static Result change(String langCode) {
    currentLanguage = langCode;
    changeLang(langCode);
    return GO_HOME;
}

I use following structure in scala view files: @Messages("color.explanation"). I tried also importing internationalization in scala view files with following: @Messages.get("color.explanation").

I added the environment variable, which is mentioned in another stackoverflow article and another stackoverflow article. But this didn't help.

Translations work perfectly by clicking except Finnish special characters. I get "N�ytet��n" instead of "Näytetään". What can be the reason, do you know any solution to this problem?

Community
  • 1
  • 1
alpalp1977
  • 59
  • 1
  • 9

2 Answers2

4

Check encoding of messages files, i.e. Idea for some reason creates messages.xy files initially with iso-8859-1 encoding - it is probably because Standard Java API is designed to use ISO 8859-1 encoding for the properties file (IntelliJ docs).

To switch to utf-8 in Idea you need first Mark as Plain text, switch the encoding and finally Mark as properties the file again.

Of course it's quite possible that you use other IDE/text editor, anyway file's encoding is first thing you need to check,I can ensure you that Play supports perfectly messages files even in Chinese if they are encoded properly.

biesior
  • 55,576
  • 10
  • 125
  • 182
  • Hi, I am encoding the view files and messages files in following with notepad++: UTF-8 (gives compilation errors), UTF-8 without BOM (no errors, but still getting weird chars), ANSI (same as UTF-8 without BOM) – alpalp1977 Mar 07 '14 at 22:08
  • Wrong encoding is almost certainly the problem. We also have a project with many different languages, including Finnish, and they all work fine. IDEA does have a habit of switching the encoding as well as many other editors. So it is very important to ensure it is UTF-8. The other thing is that once you have messed up encodings you might need some hacking to get them back again. – jodyfanning May 06 '14 at 09:05
  • When checking with notepad++ I wasn't able to change the encodings, yesterday I googled about changing encodings and tried with another (PsPad) editor. Thanks for your answers biesior and jody. – alpalp1977 May 07 '14 at 07:07
  • TIP: notepad++ is cool, but there are much nicer IDE's for working with Play, ie. Intellij Idea, which has support for Play 2.x – biesior May 07 '14 at 08:05
0

There are two reasons that immediately come to mind:

  1. You've got your messages file setup incorrectly. What I suspect you have is:

    color.explanation=Näytetään
    

    While what you should have is

    color.explanation=N\u00E4ytet\u00E4\u00E4n
    

    Not sure how you're building this, but both Maven and Ant can automatically translate the first form into the second form. Java is a bit weird about this, and I'm not sure why, but this is what you have to do. See this question for more on this topic.

  2. You may not be setting your Content-Type header correctly. What I would expect is something like this:

    Content-Type:text/html; charset=utf-8
    

    You can use, e.g., Google Chrome's Developer Tools to see what exactly is being sent back. If you're not sending back the right charset, it might just be that your browser is unable to figure out how to display that character. I don't know much about the Play Framework, so if this is your issue, I don't know how to resolve it.

Hopefully this will provide some insight and at least eliminate a couple of possibilities.

Community
  • 1
  • 1
ipsi
  • 2,049
  • 18
  • 23
  • I am trying to set the Content-type by: 'response().setContentType("text/html; charset=utf-8");', in my controller, but that doesn't help – alpalp1977 Mar 07 '14 at 22:19
  • 1
    This isn't valid for Play. In Play the message resource files are not normal Java properties, they must be in UTF-8 encoding. – jodyfanning May 06 '14 at 09:08
  • Oh right - thanks for that. All the Java frameworks that I've used have, that I can recall, expected standard Java I18N properties files. – ipsi May 07 '14 at 05:52