Play! Framework I18n

i18n = Internationalization: i, then 18 letters, then n
l10n = Localization: l, then 10 letters, then n

Internationalization is important to this world’s website and applications.
Play! Framework provide good I18n interface, you can use I18n to specify your language easily.

add config to application.conf

1
play.i18n.langs = [ "en", "en-US", "fr" ]

add messages.xx files to conf/ folder

messages.ja
messages.cn
messages.en

1
2
3
messages.en:
info.error=You aren''t logged in!
example.formatting=When using MessageFormat, '''{0}''' is replaced with the first parameter.

Controller setting

At controllet, you need add ‘MessagesApi’

1
2
3
4
import javax.inject.Inject
import play.api.i18n.{I18nSupport, MessagesApi}

class I18nController @Inject() (val messagesApi: MessagesApi) extends Controller with I18nSupport {

use I18n

1
2
3
4
5
6
7
import play.api.i18n.Messages

need add implicit value for message :
(implicit message:Message)

Messages("info.error") == "You aren't logged in!"
Messages("example.formatting", "good man") == "When using MessageFormat, good man is replaced with the first parameter."