Giter VIP home page Giter VIP logo

resource4j's Introduction

resource4j - resource loader for Java

Overview

Resource4j library is a replacement for Java ResourceBundle mechanism that supports complex i18n scenarios of large and legacy applications and provides safe access to key/value application configuration and arbitrary resource files. With well-designed API based on fluent DSL it is a solution for i18n just like SLF4J is a solution for logging abstraction.

Key features of this library:

  • Support of Java SE resource bundles, custom resource file formats (HOCON) and data sources (files, database etc).
  • Fluent DSL for type conversions and enforcing not-null constraints
  • Locale-based and custom resolution of values
  • Spring Framework and Thymeleaf integration, including Spring EL and JavaConfig.
  • Full support of Test-Driven Development
  • Modular architecture allows to use only the part of implementation you really need

Quick Start

  1. Add resource4j-core.jar to your classpath.
  2. Create new instance of RefreshableResources:
Resources resources = new RefreshableResources();
  1. Add resource bundles and content files to your classpath:
    /com/mycompany/data/Country-en_US.properties:
     discount=0.1
    
     # Formatting
     custom_format=MMMM d, yyyy
     today=Today is {date:custom_format}
    
     # Pluralization
     duration={count} {years;count:pluralize}
     years_one=year
     years_other=years
     
    /docs/EULA.txt:
     Lorem ipsum dolorem sit amet.
  2. Get some value:
BigDecimal localDiscount = resources.get(key(Country.class, "discount"), in(Locale.US))
			.notNull()
			.as(BigDecimal.class); // 0.1

String date = resources.get(key(Country.class, "today"), in(Locale.US).with("date", LocalDate.of(2018, 1, 1)))
            .notNull()
            .asIs(); // "January 1, 2018"

String duration = resources.get(key(Country.class, "duration"), in(Locale.US).with("count", 3))
            .notNull()
            .asIs(); // "3 years"
  1. Load content:
String eulaText = resources.contentOf("/docs/EULA.txt", in(Locale.US))
			.parsedTo(string())
			.asIs();

Dependency management

If you are using Maven, please, add following lines to your POM file:

	<dependency>
		<groupId>com.github.resource4j</groupId>
		<artifactId>resource4j-core</artifactId>
		<version>3.1.3</version>
	</dependency>

For integration with Spring and (optionally) Thymeleaf, add following:

	<dependency>
		<groupId>com.github.resource4j</groupId>
		<artifactId>resource4j-spring</artifactId>
		<version>3.1.3</version>
	</dependency>

For using Resource4j as message provider in Thymeleaf, add following:

	<dependency>
		<groupId>com.github.resource4j</groupId>
		<artifactId>resource4j-thymeleaf3</artifactId>
		<version>3.1.3</version>
	</dependency>

To add support of HOCON or XStream configuration files add Extras library:

    <dependency>
        <groupId>com.github.resource4j</groupId>
        <artifactId>resource4j-extras</artifactId>
        <version>3.1.3</version>
    </dependency>

Learn more

  1. Basics
  2. Configuring resources
  3. Integration with Spring Framework
  4. Integration with Thymeleaf
  5. Extras

resource4j's People

Contributors

ivan-gammel avatar

Watchers

James Cloos avatar Dasha Kobzeva 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.