Skip to content
This repository has been archived by the owner on Apr 30, 2019. It is now read-only.

Latest commit

 

History

History
58 lines (43 loc) · 3.51 KB

File metadata and controls

58 lines (43 loc) · 3.51 KB

Internationalized Service

This recipe demonstrates how to create a stateless service in Lagom for Java that uses Play's Internationalization Support.

Implementation details

The hello-i18n-impl/src/main/resources directory contains configuration:

The implementation is in HelloServiceImpl:

Testing the recipe

You can test this recipe using 2 separate terminals.

On one terminal start the service:

mvn lagom:runAll

On a separate terminal, use curl to request messages in various languages. There are two ways to do it, by passing a locale parameter in the URL, or by specifying the 'Accept-Language' header.

First, with the URL parameter:

$ curl http://localhost:9000/api/hello/en/Alice && echo
Hello, Alice!
$ curl http://localhost:9000/api/hello/es/Alice && echo
¡Hola, Alice!
$ curl http://localhost:9000/api/hello/de-DE/Alice && echo
Hallo, Alice!
$ curl http://localhost:9000/api/hello/fr-FR/Alice && echo # missing, falls back to en
Hello, Alice!

Alternatively with the 'Accept-Language' header:

$ curl http://localhost:9000/api/hello/Alice && echo # default, uses en
Hello, Alice!
$ curl -H 'Accept-Language: es-ES' http://localhost:9000/api/hello/Alice && echo # with a full locale code
¡Hola, Alice!
$ curl -H 'Accept-Language: es' http://localhost:9000/api/hello/Alice && echo # just the language code
¡Hola, Alice!
$ curl -H 'Accept-Language: de-CH' http://localhost:9000/api/hello/Alice && echo # missing, falls back to en
Hello, Alice!
$ curl -H 'Accept-Language: de-CH, de' http://localhost:9000/api/hello/Alice && echo # or you can specify a list to use the first match
Hallo, Alice!