messageformatter

Message formatter using SpringFramework

License

License

Categories

Categories

ORM Data
GroupId

GroupId

com.github.mygreen
ArtifactId

ArtifactId

messageformatter
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

jar
Description

Description

messageformatter
Message formatter using SpringFramework
Project URL

Project URL

https://mygreen.github.io/messageformatter/
Project Organization

Project Organization

mygreen
Source Code Management

Source Code Management

https://github.com/mygreen/messageformatter

Download messageformatter

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mygreen/messageformatter/ -->
<dependency>
    <groupId>com.github.mygreen</groupId>
    <artifactId>messageformatter</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mygreen/messageformatter/
implementation 'com.github.mygreen:messageformatter:0.2'
// https://jarcasting.com/artifacts/com.github.mygreen/messageformatter/
implementation ("com.github.mygreen:messageformatter:0.2")
'com.github.mygreen:messageformatter:jar:0.2'
<dependency org="com.github.mygreen" name="messageformatter" rev="0.2">
  <artifact name="messageformatter" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mygreen', module='messageformatter', version='0.2')
)
libraryDependencies += "com.github.mygreen" % "messageformatter" % "0.2"
[com.github.mygreen/messageformatter "0.2"]

Dependencies

compile (4)

Group / Artifact Type Version
org.springframework : spring-context jar 5.0.18.RELEASE
org.slf4j : slf4j-api jar 1.7.25
org.slf4j : jcl-over-slf4j jar 1.7.25
ch.qos.logback : logback-classic jar 1.2.3

provided (4)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.12
org.apache.commons : commons-jexl jar 2.1.1
javax.validation : validation-api jar 2.0.1.Final
org.hibernate.validator : hibernate-validator jar 6.1.5.Final

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-engine jar 5.5.2
org.assertj : assertj-core jar 3.13.2
org.springframework : spring-test jar 5.0.18.RELEASE

Project Modules

There are no modules declared in this project.

Maven Central Javadocs Build Status SonarQube

MessageFormatter

Spring Frameworkの MessageSource を使い、表示メッセージをフォーマットするライブラリです。

メッセージ中にパラメータを渡したり、EL式を評価したりできます。

Licensee

MIT License

Dependency

  • Java 11+
  • SpringFramework 5.0+
  • BeanValidation 2.0(optional)
  • JEXL 2.1(optional)

Setup

App dependency. ex) pom.xml

<dependency>
	<groupId>com.github.mygreen</groupId>
	<artifactId>messageformatter</artifactId>
	<version>0.2</version>
</dependency>

How to use

  1. Define message property
test.message=the ${#formatter.format('%1.2f', #validatedValue)} is invalid. Please must be between {min} and {max}.
  1. Create instance the MessageFormatter
// MessageSource
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.addBasenames("your_messages");
messageSource.setDefaultEncoding("UTF-8");
messageSource.setFallbackToSystemLocale(false);

// MessageInterpolator with ExpressionEvaluator
// ex) SpEL
MessageInterpolator messageInterpolator = new MessageInterpolator(new SpelExpressionEvaluator());

MessageFormatter messageFormatter = new MessageFormatter(messageSource, messageInterpolator);
  1. Set param and format.
double value = 3.1;
String message = messageFormatter.create("test.message")
    .param("validatedValue", value)
    .param("min", 1)
    .param("max", 10)
    .format();

Documentation

Versions

Version
0.2
0.1