Releases: projectfluent/fluent.js
@fluent/bundle 0.15.0
-
Migrate to TypeScript. (#436)
The source code of
@fluent/bundle
has been ported to TypeScript. There
are no breaking changes to the public API.A new export has been added for TS consumers:
FluentValue
which is a
union of theFluentType
class andstring
. This reflects the
implementation detail of@fluent/bundle
which treats primitive strings
as validFluentType
instances.The ES module files are now published into the
esm
directory. It also
contains the type definitions for TS consumers. Thesrc
directory 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
hasOwnProperty
toformatPattern
. (#428)
@fluent/dom 0.6.0
- Update
@fluent/dom
to work with@fluent/bundle
0.14
@fluent/react 0.10.0
-
Update to
@fluent/bundle
0.14.0.This version of
@fluent/react
can be used with the newFluentBundle
API released in@fluent/bundle
0.14.0. -
Report formatting errors from
Localized
andgetString
. (#412)Formatting errors are now printed to the console. In the future,
@fluent/react
will allow finer-grained control over rpeorting errors.
See #411.
@fluent/bundle 0.14.0
FluentBundle
API
-
Remove
FluentBundle.addMessages
.Use
FluentBundle.addResource
instead, 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
Pattern
is private.Raw messages returned from
getMessage
have their values and attributes
stored in aPattern
type. 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.Patterns
are black boxes and are meant to be used as
arguments toformatPattern
. -
Rename
FluentBundle.format
toformatPattern
.formatPattern
only accepts validPatterns
as 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
formatPattern
whenerrors
are not passed as an argument.The old
format()
method would silence all errors if the thrid argument,
theerrors
array was not given.formatPattern
changes 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
errors
array as the third argument to
formatPattern
. All errors encountered during the formatting will be
then appended to the array. In this scenario,formatPattern
is
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.fromString
method.Parse resources by using the constructor:
new FluentResource(text)
. -
Do not extend
Map
.FluentResources
are now instances of their own class only. -
Add
FluentResource.body
.The
body
field is an array storing the resource's parsed messages and
terms.
FluentType
API
-
FluentNumber
must be instantiated with a number.The constructor doesn't call
parseFloat
on the passed value anymore. -
FluentDateTime
must 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 influent
0.12. This note is meant
to clearly indicate thatfluent
supports 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
ftl
dedent helper.The
ftl
dedent 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/syntax
from now on.
fluent-sequence 0.3.0
- Deprecate
fluent-sequence
in favor of@fluent/sequence
.
fluent-react 0.9.0
- Deprecate
fluent-react
in favor of@fluent/react
.
fluent-react 0.8.5
- Accept
fluent
0.13.x as a peer dependency. - Fix the rendering of empty
<Localized/>
. (#378)