Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top