• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

KarelCemus/play-i18n: Multi-format localization plugin for Play framework

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

KarelCemus/play-i18n

开源软件地址(OpenSource Url):

https://github.com/KarelCemus/play-i18n

开源编程语言(OpenSource Language):

Scala 99.4%

开源软件介绍(OpenSource Introduction):

Multi-format Messaging module
for Play framework

Note: This version supports Play framework 2.8.x. For compatibility with previous versions see previous releases.

Play framework 2 is delivered with default Messaging module using property files. The syntax is not much convenient as involves a lot of repetition, thus this module delivers an alternative to supporting YAML format for messages including all features of the language.

Build Status

How to add the module into the project

To your SBT build.sbt add the following lines:

libraryDependencies ++= Seq(
  // YAML localization module
  "com.github.karelcemus" %% "play-i18n" % "2.2.0"
)

And add the following line into your configuration to disable the original Play's implementation:

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

How to use the this localization module

The end-user API remains same. The module is smoothly connected to the current I18n which delivers MessagesApi as a single access point.

Example:

messages: MessagesApi
messages( "my.simple.key", "With", 3, "parameters" )

The module supports multiple message file formats. Right now, it supports the property files for backward compatibility and YAML files for their convenient syntax. The base file name remains same as is defined by Play framework: messages[.lang] where lang is optional for a particular language mutation. For YAML files the name pattern is very similar: messages.yaml[.lang] again with the optional language. All these files are looked up at the classpath.

Example of property file:

my.simple.key = The key resolves to {0} {1} {2}
my.simple.value = Some text
my.another.key = Another localization key

Example of YAML file:

my:
  simple:
    key: The key resolves to {0} {1} {2}
    value: Some text
  another.key: = Another localization key

The YAML file format brings some beautiful features such as:

  • key hierarchy
  • multi-line strings
  • sub-tree replacement (naming one tree and referencing it elsewhere)

For full list of features see Wikipedia

Note: Although YAML supports data types, the module ignores them to preserve the compatibility with the MessagingAPI.

Configuration

There is already default configuration but it can be overwritten in your conf/application.conf file.

Key Type Default Description
play.i18n.path String empty Prefix of messages files
play.i18n.formats.properties Boolean true Enables the format
play.i18n.formats.yaml Boolean true Enables the format

Worth knowing to avoid surprises

The library configuration automatically disables default Messaging module and enables custom implementation. You do not have to take care of it but it is good to be aware of it, because it replaces the implementation.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap