Coder Social home page Coder Social logo

rolman243 / play-i18n-hocon Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marcospereira/play-i18n-hocon

0.0 1.0 0.0 38 KB

A Playframework module to use HOCON for i18n instead of properties

Home Page: https://marcospereira.github.io/play-i18n-hocon/

License: Apache License 2.0

Scala 98.91% Shell 1.09%

play-i18n-hocon's Introduction

Play I18n using HOCON

Build Status Build status codecov Codacy Badge

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" % "0.0.2"

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.

play-i18n-hocon's People

Contributors

marcospereira avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.