Skip to content

Commit efd579f

Browse files
committed
@fluent/bundle 0.14.0
1 parent fe71782 commit efd579f

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

fluent-bundle/CHANGELOG.md

+108
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,113 @@
11
# Changelog
22

3+
## @fluent/bundle 0.14.0 (July 30, 2019)
4+
5+
### `FluentBundle` API
6+
7+
- Remove `FluentBundle.addMessages`.
8+
9+
Use `FluentBundle.addResource` instead, combined with a `FluentResource`
10+
instance.
11+
12+
- Remove `FluentBundle.messages`.
13+
14+
The list of messages in the bundle should not be inspected. If you need
15+
to do it, please use the tooling parser from `@fluent/syntax`.
16+
17+
- Change the shape returned by `FluentBundle.getMessage`.
18+
19+
The method now returns the following shape:
20+
21+
{value: Pattern | null, attributes: Record<string, Pattern>}
22+
23+
- The internal representtion of `Pattern` is private.
24+
25+
Raw messages returned from `getMessage` have their values and attributes
26+
stored in a `Pattern` type. The internal representation of this type is
27+
private and implementation-specific. It should not be inspected nor used
28+
for any purposes. The implementation may change without a warning in
29+
future releases. `Patterns` are black boxes and are meant to be used as
30+
arguments to `formatPattern`.
31+
32+
- Rename `FluentBundle.format` to `formatPattern`.
33+
34+
`formatPattern` only accepts valid `Patterns` as the first argument. In
35+
practice, you'll want to first retrieve a raw message from the bundle via
36+
`getMessage`, and then format the value (if present) and the attributes
37+
separately.
38+
39+
```js
40+
let message = bundle.getMessage("hello");
41+
if (message.value) {
42+
bundle.formatPattern(message.value, {userName: "Alex"});
43+
}
44+
```
45+
46+
The list of all attributes defined in the message can be obtained with
47+
`Object.keys(message.attributes)`.
48+
49+
- Throw from `formatPattern` when `errors` are not passed as an argument.
50+
51+
The old `format()` method would silence all errors if the thrid argument,
52+
the `errors` array was not given. `formatPattern` changes this behavior
53+
to throwing on the first encountered error and interrupting the
54+
formatting.
55+
56+
```js
57+
try {
58+
bundle.formatPattern(message.value, args);
59+
} catch (err) {
60+
// Handle the error yourself.
61+
}
62+
```
63+
64+
It's still possible to pass the `errors` array as the third argument to
65+
`formatPattern`. All errors encountered during the formatting will be
66+
then appended to the array. In this scenario, `formatPattern` is
67+
guaranteed to never throw because of errors in the translation.
68+
69+
```js
70+
let errorrs = [];
71+
bundle.formatPattern(message.value, args, errors);
72+
for (let error of errors) {
73+
// Report errors.
74+
}
75+
```
76+
77+
### `FluentResource` API
78+
79+
- Remove the static `FluentResource.fromString` method.
80+
81+
Parse resources by using the constructor: `new FluentResource(text)`.
82+
83+
- Do not extend `Map`.
84+
85+
`FluentResources` are now instances of their own class only.
86+
87+
- Add `FluentResource.body`.
88+
89+
The `body` field is an array storing the resource's parsed messages and
90+
terms.
91+
92+
### `FluentType` API
93+
94+
- `FluentNumber` must be instantiated with a number.
95+
96+
The constructor doesn't call `parseFloat` on the passed value anymore.
97+
98+
- `FluentDateTime` must be instantiated with a number.
99+
100+
The constructor doesn't call `new Date()` on the passed value anymore.
101+
The date is stored as the numerical timestamp, in milliseconds since the
102+
epoch.
103+
104+
### Formatting Changes
105+
106+
- Report errors from instantiating Intl objects used for formatting.
107+
- Report errors from functions, including built-in functions.
108+
- Format numbers and dates to safe defaults in case or errors. (#410)
109+
- When a transform function is given, transform only `TextElements`.
110+
3111
## @fluent/bundle 0.13.0 (July 25, 2019)
4112

5113
- Rename `fluent` to `@fluent/bundle`.

fluent-bundle/package.json

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

0 commit comments

Comments
 (0)