A Java library that implements Mozillas Fluent project.
<repositories>
<repository>
<id>quickwrite-net-fluent4j</id>
<url>https://dl.cloudsmith.io/public/quickwrite-net/fluent4j/maven/</url>
</repository>
</repositories><dependencies>
<dependency>
<groupId>net.quickwrite</groupId>
<artifactId>fluent-builder</artifactId>
<version>{{package-version}}</version>
</dependency>
</dependencies>repositories {
maven {
url "https://dl.cloudsmith.io/public/quickwrite-net/fluent4j/maven/"
}
}dependencies {
implementation 'net.quickwrite:fluent-builder:{{package-version}}'
}The fluent4j library is a Java implementation of Mozillas Fluent project that
intends to be extensible by default.
This means that custom constructs can be added to the basic fluent syntax so that the translation files can be used for the projects exact needs.
So that the translation files can be used the files need to be parsed first:
ResourceParserresourceParser = ResourceParserBuilder.defaultParser();
FluentResourceresource = resourceParser.parse(FluentIteratorFactory.fromString("""test = This is your fluent fileemails = You have { $unreadEmails } unread emails."""));After you've created a single or multiple Resources you can bundle them in a Bundle with other data for use:
FluentBundlebundle = FluentBundleBuilder.builder(Locale.ENGLISH)
.addResource(resource)
.build();And now you can use the different messages for translation:
System.out.println(bundle.resolveMessage("test", StringResultFactory.construct()).get());This is your fluent fileAnd you can also provide arguments for the messages:
FluentArgumentsarguments = ArgumentListBuilder.builder()
.add("unreadEmails", 5)
.build();
System.out.println(bundle.resolveMessage("emails", arguments, StringResultFactory.construct()).get());You have 5 unread emails.This project is licensed under the permissive Apache 2.0 license.