|
1 | 1 | # Changelog
|
2 | 2 |
|
| 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 | + |
3 | 111 | ## @fluent/bundle 0.13.0 (July 25, 2019)
|
4 | 112 |
|
5 | 113 | - Rename `fluent` to `@fluent/bundle`.
|
|
0 commit comments