Help
Translate Play Framework Messages files

🔗What are Play Framework Messages files?
Play Framework Messages files are the language files used to localize Play Framework applications. They use a simplified Java properties format where translation keys are mapped to their values using = or : separators.
Unlike standard Java properties files that use .properties extensions, Play Framework uses files named messages, messages.en, messages.fr, etc., where the locale code is the file extension.
WebTranslateIt is a software localization platform that can help localize Play Framework Messages files.
🔗Play Framework Messages file example
Here’s an example of a Play Framework messages file. WebTranslateIt will import each key-value pair as a segment. Comments in the file will be imported as instructions.
messages.en
# Application messages
hello = Hello
welcome = Welcome to our application
greeting.morning = Good morning
greeting.evening = Good evening
messages.fr
# Messages de l'application
hello = Bonjour
welcome = Bienvenue dans notre application
greeting.morning = Bonjour
greeting.evening = Bonsoir
Keys can use dots to create namespaces (e.g., greeting.morning).
Key-values can be separated by an equal sign (=) or by a colon (:).
key = value
key2=value
key3: hey!
key4 : hello!
Comments and instructions can start with # or !.
# this is a developer instruction
key = value
! The exclamation mark can also mark text as an instruction.
key2 = value
🔗Auto-detection
WebTranslateIt automatically detects Play Framework Messages files based on their filename pattern:
messages(no extension)messages.en,messages.fr,messages.de, etc.messages.en-US,messages.fr-CA, etc.messages.en_US,messages.fr_CA, etc.
The file content must also follow the Java properties format with key-value pairs.
🔗Magic Comments
This file handler supports the following magic comments:
- Comments containing
[MAXCHAR=xx]will set a max character limit toxx. Example:# [MAXCHAR=20] - Comments containing
[LABEL=xxxx]will assign the label toxxxx. Example:# [LABEL=new feature]
🔗Encoding
Play Framework Messages files are typically UTF-8 encoded. WebTranslateIt will preserve the encoding of your source files.
You can force the encoding of the files by adding a special comment at the very top of your master file:
# encoding: UTF-8
hello = Hello
welcome = Welcome
🔗Play Framework Internationalization
In Play Framework, you configure your supported languages in conf/application.conf:
play.i18n.langs = [ "en", "fr", "de" ]
Then you can use the messages in your templates:
Scala:
@import play.api.i18n._
@(implicit messages: Messages)
<h1>@messages("hello")</h1>
<p>@messages("welcome")</p>
Java:
public Result index(Http.Request request) {
Messages messages = messagesApi.preferred(request);
String hello = messages.at("hello");
return ok(views.html.index.render(messages));
}
🔗Variable Placeholders
Play Framework supports variable placeholders using Java’s MessageFormat syntax:
greeting = Hello {0}!
welcome.user = Welcome {0}, you have {1} messages.
In your code:
messages("greeting", "John") // Hello John!
messages("welcome.user", "Jane", 5) // Welcome Jane, you have 5 messages.
🔗How to Translate Play Framework Messages Files?
It is easy to translate Play Framework Messages files with WebTranslateIt. In a project, upload your source messages file in the File Manager and translate it on the Translation Interface.
The tools included in WebTranslateIt, such as Batch Operations, the Translation Memory or Machine Translation can help you translate that file automatically, faster and cost effectively.