Book Image

Play Framework essentials

By : Julien Richard-Foy
Book Image

Play Framework essentials

By: Julien Richard-Foy

Overview of this book

This book targets Java and Scala developers who already have some experience in web development and who want to master Play framework quickly and efficiently. This book assumes you have a good level of knowledge and understanding of efficient Java and Scala code.
Table of Contents (9 chapters)
8
Index

Serving content in several languages


Play comes with handy support for internationalization so that you can define the messages of your application in several languages and automatically select the language to use according to the user preferences (as defined by the Accept-Language request header).

When a user performs a request to a server from his web browser, this one usually sets an Accept-Language header according to the user preferences. For instance, in my case, it is the following:

Accept-Language:en,en-US;q=0.8,fr;q=0.6,fr-FR;q=0.4

This means that the language I prefer to read is English and then French. The preference level is defined by the q factor. If there is no q factor associated with a language (for instance, en, in the preceding code), its value defaults to 1 (highest preference).

So, when I request a page, the server should serve the English version of the page if it has one, or the French version. This means that the server has to choose, among the languages it supports,...