translate is a functional java translation library.
To include it in your project using maven add the dependency:
<dependency>
<groupId>com.github.chisui.translate</groupId>
<artifactId>translate</artifactId>
<version>0.1.0</version>
</dependency>
The two core components of this library are the Translator
and TranslationHint
. A TranslationHint
provides information to a Translator
to create a translation.
Create a Translator
Translator translator = Translator.of(
MessageLookup.of(MessageSource.ofResouceBundle("translations")),
Format.ofMessageFormat());
This creates a Translator
that looks for in the ResourceBundle
"translations"
and formats messages using MessageFormat
.
Create a TranslationHint
TranslationHint hint = TranslationHint
.of("key")
.withArguments(arg0, arg1, ...)
.withFallback("fallback {0} {1}");
Translate the hint
String translation = translator.translate(hint);