marcospereira / play-i18n-hocon   1.0.1

Apache License 2.0 Website GitHub

A Playframework module to use HOCON for i18n instead of properties

Scala versions: 2.12 2.11

Play I18n using HOCON

Build Status Build status codecov Codacy Badge Maven

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.

How to use

Just follow the steps below:

Add Module Dependency

Add the dependency to your build.sbt file:

libraryDependencies += "com.github.marcospereira" %% "play-hocon-i18n" % "1.0.1"

Disable built-in I18n Module

Add the following line to your conf/application.conf file:

play.modules.disabled += play.api.i18n.I18nModule

Enable HOCON I18n Module

Add the following line to your conf/application.conf file:

play.modules.enabled += com.marcospereira.play.i18n.HoconI18nModule

Write your message files with HOCON syntax

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.en conf/messages.en.conf
conf/messages.en-US conf/messages.en-US.conf

License

Copyright 2016 Marcos Pereira

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.