fluent 1.0.1+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

Fluent #

This is a Dart runtime implementation of Project Fluent, a localization framework designed to unleash the entire expressive power of natural language translations.

Project Fluent keeps simple things simple and makes complex things possible. The syntax used for describing translations is easy to read and understand. At the same time it allows, when necessary, to represent complex concepts from natural languages like gender, plurals, conjugations, and others.

Getting Started #

Learn the FTL syntax #

FTL is a localization file format used for describing translation resources. FTL stands for Fluent Translation List.

FTL is designed to be simple to read, but at the same time allows to represent complex concepts from natural languages like gender, plurals, conjugations, and others.

hello-user = Hello, { $username }!

In order to use fluent.runtime, you will need to create FTL files. Read the Fluent Syntax Guide <http://projectfluent.org/fluent/guide/>_ in order to learn more about the syntax.

Using FluentBundle #

Once you have some FTL files, you can generate translations using the fluent package. You start with the FluentBundle class:

import 'package:fluent/fluent.dart';

You pass a locale to the constructor:

final bundle = FluentBundle('en-GB');

You must then add messages. These would normally come from a .ftl file stored on disk, here we will just add them directly:

bundle.addMessages('''
welcome = Welcome to this great app!
greet-by-name = Hello, { $name }!
''');

To generate translations, use the format method, passing a message ID and an optional dictionary of substitution parameters. If the the message ID is not found, null is returned. Otherwise, as per the Fluent philosophy, the implementation tries hard to recover from any formatting errors and generate the most human readable representation of the value.

List<Error> errors = [];
translated = bundle.format('welcome', errors: errors)
translated = bundle.format('greet-by-name', args: {'name': 'Jane'}, errors: errors)

Known limitations and bugs #

  • We do not yet support NUMBER(..., currencyDisplay="...", minimumSignificantDigits="...", maximumSignificantDigits=".. ")

  • Most options to DATETIME are not yet supported.

Help with the above would be welcome!

[1.0.0] - Feb 24, 2020 #

  • Initial release.

[1.0.1] - Mar 6, 2020 #

  • Fixed selector failed with string type

example/main.dart

import 'package:fluent/fluent.dart';

void main() {
    FluentBundle bundle = FluentBundle("en-GB");
		bundle.addMessages('''your-score =
    { NUMBER(\$score, minimumFractionDigits: 1) ->
        [0.0]   You scored zero points. What happened?
       *[other] You scored { NUMBER(\$score, minimumFractionDigits: 1) } points.
    }''');
		String translated = bundle.format("your-score", args: {'score': 0.0});
		print(translated);
		translated = bundle.format("your-score", args: {'score': 3.14});
		print(translated);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fluent: ^1.0.1+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fluent/fluent.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
70
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Fix lib/src/builtin.dart. (-1 points)

Analysis of lib/src/builtin.dart reported 2 hints:

line 3 col 13: Name non-constant identifiers using lowerCamelCase.

line 28 col 13: Name non-constant identifiers using lowerCamelCase.

Fix lib/src/resolver.dart. (-0.50 points)

Analysis of lib/src/resolver.dart reported 1 hint:

line 2 col 8: Don't import implementation files from another package.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
intl ^0.16.0 0.16.1
Transitive dependencies
path 1.7.0
Dev dependencies
test ^1.9.4