Skip to content

Latest commit

 

History

History
87 lines (73 loc) · 2.39 KB

README.md

File metadata and controls

87 lines (73 loc) · 2.39 KB

fluent4j

A Java library that implements Mozillas Fluent project.

Installation

Maven

<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>

Gradle

repositories {
    maven {
        url "https://dl.cloudsmith.io/public/quickwrite-net/fluent4j/maven/"
    }
}
dependencies {
    implementation 'net.quickwrite:fluent-builder:{{package-version}}'
}

What is fluent4j?

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.

Usage

So that the translation files can be used the files need to be parsed first:

ResourceParser resourceParser = ResourceParserBuilder.defaultParser();

FluentResource resource = resourceParser.parse(FluentIteratorFactory.fromString("""
test = This is your fluent file

emails = 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:

FluentBundle bundle = 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 file

And you can also provide arguments for the messages:

FluentArguments arguments = ArgumentListBuilder.builder()
                                               .add("unreadEmails", 5)
                                               .build();

System.out.println(bundle.resolveMessage("emails", arguments, StringResultFactory.construct()).get());
You have 5 unread emails.

License

This project is licensed under the permissive Apache 2.0 license.