A Playframework module to use HOCON for i18n instead of properties
HOCON (Human-Optimized Config Object Notation) and Typesafe Config are the standard way to configure Play applications. But, for Internationalization, Play uses Java Properties which don't have a syntax to structure an tree of keys used to i18n.
This plugin offers that by using HOCON as the language for I18n too, so your messages
files will be like:
pages {
signup {
title = "The Signup page"
form {
title = "The signup form"
name = "Type your name"
email = "Type your email"
password = "Type your password"
submit = "Signup now"
}
}
}
This is not meant to be used as a drop-in replacement to default built-in module since Java Properties syntax is not compatible with HOCON.
Several versions of the library are available depending on the version of the Play framework:
play vesrion | i18n hocon version |
---|---|
until 2.6 | play-i18n-hocon |
2.8 | 1.0.0 |
Just follow the steps below:
Add the dependency to your build.sbt
file:
libraryDependencies += "io.github.tino1231" %% "play2-hocon-i18n" % "1.0.0"
Add the following line to your conf/application.conf
file:
play.modules.disabled += play.api.i18n.I18nModule
Add the following line to your conf/application.conf
file:
play.modules.enabled += com.tino1231.play.i18n.HoconI18nModule
As stated before, HOCON syntax and Java Properties are not fully compatible. The good part is that HOCON loader gives clear messages about invalid syntax and you can easily fix the errors. Of course, all HOCON features are enable here. Finally, you have to rename your messages files to have a .conf
extension, per instance:
Before | After |
---|---|
conf/messages |
conf/messages.conf |
conf/messages.ja |
conf/messages.ja.conf |
conf/messages.en-US |
conf/messages.en-US.conf |
play2-i18n-hocon is a fork of play-i18n-hocon.
play-i18n-hocon has been archived.
play2-i18n-hocon is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.
play2-i18n-hocon is a fork of play-i18n-hocon. play-i18n-hocon is licensed under the Apache License, Version 2.0.