Skip to content

Commit ae1b55a

Browse files
committed
fluent 0.6.0
- 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.
1 parent 7bc49e1 commit ae1b55a

File tree

3 files changed

+80
-13
lines changed

3 files changed

+80
-13
lines changed

fluent/CHANGELOG.md

+73-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,87 @@
11
# Changelog
22

3-
## Unreleased
3+
## fluent 0.6.0 (January 31, 2018)
44

5-
- Remove MessageContext.formatToParts.
5+
- Implement Fluent Syntax 0.5.
6+
7+
- Add support for terms.
8+
- Add support for `#`, `##` and `###` comments.
9+
- Remove support for tags.
10+
- Add support for `=` after the identifier in message and term
11+
defintions.
12+
- Forbid newlines in string expressions.
13+
- Allow trailing comma in call expression argument lists.
14+
15+
In fluent 0.6.x the new Syntax 0.5 is supported alongside the old Syntax
16+
0.4. This should make migrations easier. The parser will correctly parse
17+
Syntax 0.4 comments (prefixed with `//`), sections and message
18+
definitions without the `=` after the identifier. The one exception are
19+
tags which are no longer supported. Please use attributed defined on
20+
terms instead.
21+
22+
- Add `mapContextAsync`. (#125)
23+
24+
This is the async counterpart to mapContextSync. Given an async iterable
25+
of `MessageContext` instances and an array of ids (or a single id), it
26+
maps each identifier to the first `MessageContext` which contains the
27+
message for it.
28+
29+
An ordered interable of `MessageContext` instances can represent the
30+
current negotiated fallback chain of languages. This iterable can be used
31+
to find the best existing translation for a given identifier.
32+
33+
The iterable of `MessageContexts` can now be async, allowing code like
34+
this:
35+
36+
```js
37+
async formatString(id, args) {
38+
const ctx = await mapContextAsync(contexts, id);
39+
40+
if (ctx === null) {
41+
return id;
42+
}
43+
44+
const msg = ctx.getMessage(id);
45+
return ctx.format(msg, args);
46+
}
47+
```
48+
49+
The iterable of `MessageContexts` should always be wrapped in
50+
`CachedIterable` to optimize subsequent calls to `mapContextSync` and
51+
`mapContextAsync`.
52+
53+
Because `mapContextAsync` uses asynchronous iteration you'll likely need
54+
the regenerator runtime provided by `babel-polyfill` to run the `compat`
55+
builds of `fluent`.
56+
57+
- Expose the `ftl` dedent helper.
58+
59+
The `ftl` template literal tag can be used to conveniently include FTL
60+
snippets in other code. It strips the common indentation from the snippet
61+
allowing it to be indented on the level dictated by the current code
62+
indentation.
63+
64+
```js
65+
ctx.addMessages(ftl`
66+
foo = Foo
67+
bar = Bar
68+
);
69+
```
70+
71+
- Remove `MessageContext.formatToParts`.
672
773
It's only use-case was passing React elements as arguments to
874
translations which is now possible thanks to DOM overlays (#101).
975

10-
- Rename FluentType.valueOf to FluentType.toString.
76+
- Rename `FluentType.valueOf` to `FluentType.toString1.
1177
12-
Without MessageContext.formatToParts, all use-cases for
13-
FluentType.valueOf boil down to stringification.
78+
Without `MessageContext.formatToParts`, all use-cases for
79+
`FluentType.valueOf` boil down to stringification.
1480
15-
- Remove FluentType.isTypeOf.
81+
- Remove `FluentType.isTypeOf`.
1682
1783
fluent-react's markup overlays (#101) removed the dependency on fluent's
18-
FluentType which was hardcoded as an import from fluent/compat. Without
84+
`FluentType` which was hardcoded as an import from fluent/compat. Without
1985
this dependency all imports from fluent are in the hands of developers
2086
again and they can decide to use the ES2015+ or the compat builds as they
2187
wish. As long as they do it consistently, regular instanceof checks will

fluent/README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ The `MessageContext` constructor provides the core functionality of formatting
1919
translations from FTL files.
2020

2121
```javascript
22-
import { MessageContext } from 'fluent';
22+
import { MessageContext, ftl } from 'fluent';
2323

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

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

3131
if (errors.length) {
@@ -59,7 +59,7 @@ import { MessageContext } from 'fluent';
5959
```
6060

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

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

7676
[intl-pluralrules]: https://www.npmjs.com/package/intl-pluralrules
7777
[fluent-intl-polyfill]: https://www.npmjs.com/package/fluent-intl-polyfill
78+
[babel-polyfill]: https://babeljs.io/docs/usage/polyfill/
7879
[Stage 3 proposal]:https://github.com/tc39/proposal-intl-plural-rules
7980
[env preset]: https://babeljs.io/docs/plugins/preset-env/
8081
[projectfluent.org]: http://projectfluent.org

fluent/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fluent",
33
"description": "Localization library for expressive translations.",
4-
"version": "0.4.2",
4+
"version": "0.6.0",
55
"homepage": "http://projectfluent.org",
66
"author": "Mozilla <[email protected]>",
77
"license": "Apache-2.0",

0 commit comments

Comments
 (0)