Coder Social home page Coder Social logo

quickwrite / fluent4j Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 723 KB

A Java library that implements Mozilla Fluent

License: Apache License 2.0

Java 96.82% Fluent 3.18%
java projectfluent i18n wip ftl internationalization l10n localization java-library jvm

fluent4j's Introduction

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.

fluent4j's People

Contributors

quickwrite avatar

Stargazers

 avatar  avatar

Watchers

 avatar

fluent4j's Issues

Add JavaDocs

Add JavaDocs to the API so that the API can be a lot more easily understood.

Better Error handling

With the current implementation the parser is completely stopping when it finds an error. This can be quite cumbersome as sometimes you have multiple errors in the same file which means that you need to parse it, find the errors and parse it again (and do the same thing multiple times).

It would be a lot easier if the error handling would work so that all of the errors are being reported.

The problem with this is of course that when an error is being detected the parser must be able to "recover" from this error so that it does not spit out thousands of errors as it still tries to parser the file in a specific way.
Maybe it would be sensible to create a custom error handler for a parser and when it detects an error it is correctly handling the situation.

Speed up Numbers

It seems like numbers themselves are quite slow. This should be fixed.

Implement Custom API in Interfaces

Currently the API that exists is a mixture of Classes and Interfaces.
But the user should not be using any Class, Method, etc. that is in the impl package.

This means there should be some builders in the interfaces.

Infinite Recursion leads to Crash

When the fluent message contains some infinite recursion the entire java program will crash.

For example:

message = { message }

In this case the program will just access itself and crash.


This could be fixed by checking if a term/ message has already been accessed and if this is true it will fail.

It could also be done at the parsing step by walking over the tree and checking if this is the case.

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.