beowulf13th / yaml-resource-bundle

Use a yaml files for storing messages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yaml Resource Bundle

Can be use with Spring Framework

Instructions

  • Add dependency to Maven / Gradle project:
implementation 'ru.maksimvoloshin.utility:yaml-resource-bundle:0.1'
<dependency>
    <groupId>ru.maksimvoloshin.utility</groupId>
    <artifactId>yaml-resource-bundle</artifactId>
    <version>0.1</version>
</dependency>
  • Create a little configuration:
@Bean
ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource messageSource = new YamlResourceBundleMessageSource();
    messageSource.setBasename("messages");
    messageSource.setDefaultEncoding("utf-8");
    return messageSource;
}
  • Just inject bean in a project and use as usually

Features

bundle.getString("top.sub.check");
// returns string value
bundle.getObject("top.sub-another.may-be-array");
// returns list of objects
bundle.getObject("top.sub-another.may-be-array.size");
// returns size of list
bundle.getObject("top.sub-another.may-be-array[0].text");
// returns field value of array object
bundle.getObject("top.sub-another.list-of-value[0]");
// returns array value by index

About

Use a yaml files for storing messages

License:Apache License 2.0


Languages

Language:Java 100.0%