-
Notifications
You must be signed in to change notification settings - Fork 0
ScalaI18N
A valid language code is specified by a valid ISO 639-2 language code, optionally followed by a valid ISO 3166-1 alpha-2 country code, such as fr or en_US.
To start you need to specify the languages 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 matches all languages. Additionally you can specify language-specific message files such as conf/messages.fr or conf/messages.en_US.
You can then retrieve messages using the play.api.i18n.Messages object:
val title = Messages("home.title")
All internationalization API calls take an implicit play.api.i18.Lang argument retrieved from the current scope. You can also specify it explicitly:
val title = Messages("home.title")(Lang("fr"))
Note: If you have an implicit
Requestin the scope, it will provide an implicitLangvalue corresponding to the preferred language extracted from theAccept-Languageheader and matching one the application supported languages.
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("files.summary", d.files.length, d.name)
You can retrieve the languages supported by a specific HTTP request:
def index = Action { request =>
Ok("Languages: " + request.acceptLanguages.map(_.code).mkString(", "))
}
- 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 WebServices
- Integrating with Akka
- Internationalization
- The application Global object
- Testing your application