Releases: projectfluent/fluent.js
@fluent/react 0.11.0
-
Use the official stable React Context API. (#406)
@fluent/reactused to use the legacy React Context API. Thanks to @Gregoor, we now use the official React Context API instead.@fluent/reactbundle size is now around 15% smaller (1.5 KB minified and gzipped). -
Require React 16.8+.
The switch to the new React Context API requires that we drop support for old versions of React, like 0.14 and 15. Additionally,
@fluent/reactuses hooks under the hood now, which require at least React 16.8. -
Accept
@fluent/bundle0.15 as peer dependency.
@fluent/bundle 0.15.0
-
Migrate to TypeScript. (#436)
The source code of
@fluent/bundlehas been ported to TypeScript. There
are no breaking changes to the public API.A new export has been added for TS consumers:
FluentValuewhich is a
union of theFluentTypeclass andstring. This reflects the
implementation detail of@fluent/bundlewhich treats primitive strings
as validFluentTypeinstances.The ES module files are now published into the
esmdirectory. It also
contains the type definitions for TS consumers. Thesrcdirectory has
been removed from the published packages.
@fluent/bundle 0.14.1
-
Fix a big which made placeables which resolved to long strings format as
{???}. (#439)Expressions which resolved to strings over 2500 characters long used to be
considered dangerous. This is no longer the case. Instead, there's a limit
on how many placeable can be resolved during a single call to
formatPattern, to protect from high CPU usage in deeply nested patterns. -
Fix a bug which made it impossible to pass a variable called
hasOwnPropertytoformatPattern. (#428)
@fluent/dom 0.6.0
- Update
@fluent/domto work with@fluent/bundle0.14
@fluent/react 0.10.0
-
Update to
@fluent/bundle0.14.0.This version of
@fluent/reactcan be used with the newFluentBundle
API released in@fluent/bundle0.14.0. -
Report formatting errors from
LocalizedandgetString. (#412)Formatting errors are now printed to the console. In the future,
@fluent/reactwill allow finer-grained control over rpeorting errors.
See #411.
@fluent/bundle 0.14.0
FluentBundle API
-
Remove
FluentBundle.addMessages.Use
FluentBundle.addResourceinstead, combined with aFluentResource
instance. -
Remove
FluentBundle.messages.The list of messages in the bundle should not be inspected. If you need
to do it, please use the tooling parser from@fluent/syntax. -
Change the shape returned by
FluentBundle.getMessage.The method now returns the following shape:
{value: Pattern | null, attributes: Record<string, Pattern>} -
The internal representtion of
Patternis private.Raw messages returned from
getMessagehave their values and attributes
stored in aPatterntype. The internal representation of this type is
private and implementation-specific. It should not be inspected nor used
for any purposes. The implementation may change without a warning in
future releases.Patternsare black boxes and are meant to be used as
arguments toformatPattern. -
Rename
FluentBundle.formattoformatPattern.formatPatternonly accepts validPatternsas the first argument. In
practice, you'll want to first retrieve a raw message from the bundle via
getMessage, and then format the value (if present) and the attributes
separately.let message = bundle.getMessage("hello"); if (message.value) { bundle.formatPattern(message.value, {userName: "Alex"}); }
The list of all attributes defined in the message can be obtained with
Object.keys(message.attributes). -
Throw from
formatPatternwhenerrorsare not passed as an argument.The old
format()method would silence all errors if the thrid argument,
theerrorsarray was not given.formatPatternchanges this behavior
to throwing on the first encountered error and interrupting the
formatting.try { bundle.formatPattern(message.value, args); } catch (err) { // Handle the error yourself. }
It's still possible to pass the
errorsarray as the third argument to
formatPattern. All errors encountered during the formatting will be
then appended to the array. In this scenario,formatPatternis
guaranteed to never throw because of errors in the translation.let errorrs = []; bundle.formatPattern(message.value, args, errors); for (let error of errors) { // Report errors. }
FluentResource API
-
Remove the static
FluentResource.fromStringmethod.Parse resources by using the constructor:
new FluentResource(text). -
Do not extend
Map.FluentResourcesare now instances of their own class only. -
Add
FluentResource.body.The
bodyfield is an array storing the resource's parsed messages and
terms.
FluentType API
-
FluentNumbermust be instantiated with a number.The constructor doesn't call
parseFloaton the passed value anymore. -
FluentDateTimemust be instantiated with a number.The constructor doesn't call
new Date()on the passed value anymore.
The date is stored as the numerical timestamp, in milliseconds since the
epoch.
Formatting Changes
- Report errors from instantiating Intl objects used for formatting.
- Report errors from functions, including built-in functions.
- Format numbers and dates to safe defaults in case or errors. (#410)
- When a transform function is given, transform only
TextElements.
fluent 0.13.0
-
Support Fluent Syntax 1.0.
Syntax 1.0 is the same as Syntax 0.9, and the support for it in this
release continues to be the same as influent0.12. This note is meant
to clearly indicate thatfluentsupports the first stable version of
the Syntax specification. -
Improve the fallback string in case of expression errors.
Unresolved expressions are now printed with braces around them, e.g.
{missing}rather thanmissing(#368). References to missing message
attributes now fall back to{messageId.attributeName}(#370). -
Remove the
ftldedent helper.The
ftldedent helper has moved to its own package,@fluent/dedent.
Note that its behavior has changed slightly, too. See the
README for details.
fluent-syntax 0.14.0
- Deprecate
fluent-syntax. Please use@fluent/syntaxfrom now on.
fluent-sequence 0.3.0
- Deprecate
fluent-sequencein favor of@fluent/sequence.
fluent-react 0.9.0
- Deprecate
fluent-reactin favor of@fluent/react.