-
Notifications
You must be signed in to change notification settings - Fork 0
JavaI18N
A valid language code is specified by a valid ISO Language Code, optionally followed by a valid ISO Country Code, such as fr or en-US.
To start you need to specify the language supported by your application in the conf/application.conf file:
application.langs=en,en-US,fr
You can externalize messages in the conf/messages.xxx files.
The default conf/messages file match all languages. Additionnally you specify by language messages file like conf/messages.fr or conf/messages.en_US.
Then you can retrieve messages using the play.api.i18n.Messages object:
String title = Messages.get("home.title")
You can also specify the lang explicitely:
String title = Messages.get(new Lang("fr"), "home.title")
Note: If you have a
Requestin the scope, it will provide a defaultLangvalue corresponding to the preferred language extracted from theAccept-Languageheader and matching one the application supported languages.
The messages, can be formatted using the java.text.MessageFormat library. For example:
Assuming you have message defined like:
files.summary=The disk {1} contains {0} file(s).
You can then specify parameters as:
Messages.get("files.summary", d.files.length, d.name)
You can retrieve supported language by a specific HTTP request:
public static Result index() {
return ok(request().acceptLanguages());
}
- HTTP programming
- Asynchronous HTTP programming
- The template engine
- HTTP form submission and validation
- Working with JSON
- Working with XML
- Handling file upload
- Accessing an SQL database
- Using the Cache
- Calling web services
- Integrating with Akka
- Internationalization
- The application Global object
- Testing your application