Skip to content

Commit

Permalink
fluent 0.6.0
Browse files Browse the repository at this point in the history
  - Implement Fluent Syntax 0.5.

    - Add support for terms.
    - Add support for `#`, `##` and `###` comments.
    - Remove support for tags.
    - Add support for `=` after the identifier in message and term
      defintions.
    - Forbid newlines in string expressions.
    - Allow trailing comma in call expression argument lists.

    In fluent 0.6.x the new Syntax 0.5 is supported alongside the old Syntax
    0.4. This should make migrations easier. The parser will correctly parse
    Syntax 0.4 comments (prefixed with `//`), sections and message
    definitions without the `=` after the identifier. The one exception are
    tags which are no longer supported. Please use attributed defined on
    terms instead.

  - Add `mapContextAsync`. (#125)

    This is the async counterpart to mapContextSync. Given an async iterable
    of `MessageContext` instances and an array of ids (or a single id), it
    maps each identifier to the first `MessageContext` which contains the
    message for it.

    An ordered interable of `MessageContext` instances can represent the
    current negotiated fallback chain of languages. This iterable can be used
    to find the best existing translation for a given identifier.

    The iterable of `MessageContexts` can now be async, allowing code like
    this:

    ```js
    async formatString(id, args) {
        const ctx = await mapContextAsync(contexts, id);

        if (ctx === null) {
            return id;
        }

        const msg = ctx.getMessage(id);
        return ctx.format(msg, args);
    }
    ```

    The iterable of `MessageContexts` should always be wrapped in
    `CachedIterable` to optimize subsequent calls to `mapContextSync` and
    `mapContextAsync`.

    Because `mapContextAsync` uses asynchronous iteration you'll likely need
    the regenerator runtime provided by `babel-polyfill` to run the `compat`
    builds of `fluent`.

  - Expose the `ftl` dedent helper.

    The `ftl` template literal tag can be used to conveniently include FTL
    snippets in other code. It strips the common indentation from the snippet
    allowing it to be indented on the level dictated by the current code
    indentation.

    ```js
    ctx.addMessages(ftl`
        foo = Foo
        bar = Bar
    );
    ```

  - Remove `MessageContext.formatToParts`.

    It's only use-case was passing React elements as arguments to
    translations which is now possible thanks to DOM overlays (#101).

  - Rename `FluentType.valueOf` to `FluentType.toString1.

    Without `MessageContext.formatToParts`, all use-cases for
    `FluentType.valueOf` boil down to stringification.

  - Remove `FluentType.isTypeOf`.

    fluent-react's markup overlays (#101) removed the dependency on fluent's
    `FluentType` which was hardcoded as an import from fluent/compat. Without
    this dependency all imports from fluent are in the hands of developers
    again and they can decide to use the ES2015+ or the compat builds as they
    wish. As long as they do it consistently, regular instanceof checks will
    work well.
  • Loading branch information
stasm committed Jan 31, 2018
1 parent 7bc49e1 commit ae1b55a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 13 deletions.
80 changes: 73 additions & 7 deletions fluent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,87 @@
# Changelog

## Unreleased
## fluent 0.6.0 (January 31, 2018)

- Remove MessageContext.formatToParts.
- Implement Fluent Syntax 0.5.

- Add support for terms.
- Add support for `#`, `##` and `###` comments.
- Remove support for tags.
- Add support for `=` after the identifier in message and term
defintions.
- Forbid newlines in string expressions.
- Allow trailing comma in call expression argument lists.

In fluent 0.6.x the new Syntax 0.5 is supported alongside the old Syntax
0.4. This should make migrations easier. The parser will correctly parse
Syntax 0.4 comments (prefixed with `//`), sections and message
definitions without the `=` after the identifier. The one exception are
tags which are no longer supported. Please use attributed defined on
terms instead.

- Add `mapContextAsync`. (#125)

This is the async counterpart to mapContextSync. Given an async iterable
of `MessageContext` instances and an array of ids (or a single id), it
maps each identifier to the first `MessageContext` which contains the
message for it.

An ordered interable of `MessageContext` instances can represent the
current negotiated fallback chain of languages. This iterable can be used
to find the best existing translation for a given identifier.

The iterable of `MessageContexts` can now be async, allowing code like
this:

```js
async formatString(id, args) {
const ctx = await mapContextAsync(contexts, id);

if (ctx === null) {
return id;
}

const msg = ctx.getMessage(id);
return ctx.format(msg, args);
}
```

The iterable of `MessageContexts` should always be wrapped in
`CachedIterable` to optimize subsequent calls to `mapContextSync` and
`mapContextAsync`.

Because `mapContextAsync` uses asynchronous iteration you'll likely need
the regenerator runtime provided by `babel-polyfill` to run the `compat`
builds of `fluent`.
- Expose the `ftl` dedent helper.
The `ftl` template literal tag can be used to conveniently include FTL
snippets in other code. It strips the common indentation from the snippet
allowing it to be indented on the level dictated by the current code
indentation.
```js
ctx.addMessages(ftl`
foo = Foo
bar = Bar
);
```
- Remove `MessageContext.formatToParts`.
It's only use-case was passing React elements as arguments to
translations which is now possible thanks to DOM overlays (#101).

- Rename FluentType.valueOf to FluentType.toString.
- Rename `FluentType.valueOf` to `FluentType.toString1.
Without MessageContext.formatToParts, all use-cases for
FluentType.valueOf boil down to stringification.
Without `MessageContext.formatToParts`, all use-cases for
`FluentType.valueOf` boil down to stringification.
- Remove FluentType.isTypeOf.
- Remove `FluentType.isTypeOf`.
fluent-react's markup overlays (#101) removed the dependency on fluent's
FluentType which was hardcoded as an import from fluent/compat. Without
`FluentType` which was hardcoded as an import from fluent/compat. Without
this dependency all imports from fluent are in the hands of developers
again and they can decide to use the ES2015+ or the compat builds as they
wish. As long as they do it consistently, regular instanceof checks will
Expand Down
11 changes: 6 additions & 5 deletions fluent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ The `MessageContext` constructor provides the core functionality of formatting
translations from FTL files.

```javascript
import { MessageContext } from 'fluent';
import { MessageContext, ftl } from 'fluent';

const ctx = new MessageContext('en-US');

const errors = ctx.addMessages(`
brand-name = Foo 3000
welcome = Welcome, { $name }, to { brand-name }!
const errors = ctx.addMessages(ftl`
-brand-name = Foo 3000
welcome = Welcome, { $name }, to { -brand-name }!
`);

if (errors.length) {
Expand Down Expand Up @@ -59,7 +59,7 @@ import { MessageContext } from 'fluent';
```

For legacy browsers, the `compat` build has been transpiled using Babel's [env
preset][]:
preset][]. It requires the regenerator runtime provided by [babel-polyfill][].

```javascript
import { MessageContext } from 'fluent/compat';
Expand All @@ -75,6 +75,7 @@ implementations, and information about how to get involved.

[intl-pluralrules]: https://www.npmjs.com/package/intl-pluralrules
[fluent-intl-polyfill]: https://www.npmjs.com/package/fluent-intl-polyfill
[babel-polyfill]: https://babeljs.io/docs/usage/polyfill/
[Stage 3 proposal]:https://github.com/tc39/proposal-intl-plural-rules
[env preset]: https://babeljs.io/docs/plugins/preset-env/
[projectfluent.org]: http://projectfluent.org
Expand Down
2 changes: 1 addition & 1 deletion fluent/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fluent",
"description": "Localization library for expressive translations.",
"version": "0.4.2",
"version": "0.6.0",
"homepage": "http://projectfluent.org",
"author": "Mozilla <[email protected]>",
"license": "Apache-2.0",
Expand Down

0 comments on commit ae1b55a

Please sign in to comment.