Skip to content

Releases: projectfluent/fluent.js

fluent-syntax 0.6.4 (March 7, 2018)

07 Mar 10:31
Compare
Choose a tag to compare
Pre-release
  • Whitespace-only values are now correctly parsed as null. (#159)
  • Correctly parse Patterns at EOF. (#159)
  • Serialize values with Select Expression on a new line. (#161)

fluent-react 0.6.1 (February 19, 2018)

19 Feb 17:19
Compare
Choose a tag to compare
Pre-release
  • Preserve children of wrapped components if translation value is null. (#154)

    <Localized> now special-cases translations with null values; it
    preserves the original children of the wrapped element and only sets
    translated attributes.

  • Protect void elements from translations which try to set children. (#155)

    A broken translation may have a value where none is expected.
    <Localized> components now protect wrapped void elements from having
    this unexpected value inserted as children.

  • Add a third argument to getString for fallback. (#147)

    The new third argument to the getString function in withLocalized
    wrapped components allows for definition of a fallback message in case
    the message id is not fount in the message context. The fallback message
    may also be used for extraction of source copy.

fluent 0.6.3 (February 9, 2018)

10 Feb 01:48
Compare
Choose a tag to compare
Pre-release
  • Update sinon to 4.2.2

fluent 0.4.3 (February 9, 2018)

09 Feb 13:26
Compare
Choose a tag to compare
Pre-release

This is a 0.4.x API-compatible version of fluent intended to make the migration to Fluent Syntax 0.5 easier. It includes changes to the MessageContext parser backported from fluent 0.6.0 and fluent 0.6.2.

In particular, this version brings support for 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 definitions.
  • Forbid newlines in string expressions.
  • Allow trailing comma in call expression argument lists.

The new Syntax 0.5 is supported alongside Syntax 0.4 in order to aid migrating to the new syntax. 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 attributes defined on terms instead.

fluent-dom 0.1.0 (February 9, 2018)

09 Feb 21:43
Compare
Choose a tag to compare
Pre-release

This is the first complete test release. The main change is a limitation of DOM Overlays (we're reworking more advanced features of it like element reordering) and performance improvement when working with DOM mutations.

  • Extend formatWithFallback to accept async iterator (#46)
  • Documented all methods
  • Removed DOMLocalization.prototype.translateRoot method
  • Simplified initial version of DOM Overlays (to be extended in 0.2) (#71)
    • Only children of the white-listed types are allowed now. It's not possible
      anymore to put elements of other types in the source HTML to make exceptions.
    • The identity of the source element's children is explicitly not kept
      anymore. This allows us to treat the translation DocumentFragment as the
      reference for iteration over child nodes.
    • The overlay function is also no longer recursive. Any nested HTML
      will be lost and only its textContent will be preserved.
  • Added data-l10n-attrs to allow for whitelisting localizable attributes (#70)
  • Added a guard to prevent registering nested roots (#72)
  • Added a guard to prevent leaking attributes between translations (#73)
  • Added a performance optimization coalescing all translations from mutations
    per animation frame (#113)

fluent 0.6.2 (February 8, 2018)

08 Feb 16:36
Compare
Choose a tag to compare
Pre-release
  • Correctly parse empty comment lines. (#149)
  • Forbid null attribute and variant values. (part of #150)

fluent-syntax 0.6.2 (February 8, 2018)

08 Feb 16:35
Compare
Choose a tag to compare
Pre-release
  • Inline Patterns may start with any character. (#150)

    }, ., * and [ are only special when they appear at the beginning of indented Pattern lines. When a Pattern starts on the same line as id = or [variant key], its first character doesn't carry any special meaning and it may be one of those four ones as well.

    This also fixes a regression from 0.6.0 where a message at the EOF without value nor attributes was incorrectly parsed as a message with an empty Pattern rather than produce a syntax error.

  • Ensure CallExpression's args are always an array, even if empty.

fluent-react 0.6.0 (February 1, 2018)

01 Feb 20:45
Compare
Choose a tag to compare
Pre-release
  • Allow limited markup in translations. (#101)

    Translations in Fluent can now include simple HTML-like markup. Elements found in translations will be matched with props passed to <Localized>. These props must be React elements. Their content will be replaced by the localizable content found for the corrensponding markup in the translation.

    This is a breaking change from fluent-react 0.4.1. See migration notes below.

    send-comment = <confirm>Send</confirm> or <cancel>go back</cancel>.
    <Localized
        id="send-comment"
        confirm={
            <button onClick={sendComment}></button>
        }
        cancel={
            <Link to="/"></Link>
        }
    >
        <p>{'<confirm>Send</confirm> or <cancel>go back</cancel>.'}</p>
    </Localized>

    The rendered result will include the props interpolated into the translation:

    <p>
        <button onClick={sendComment}>Send</button> or <Link to="/">go back</Link>.
    </p>

    When naming markup elements it's possible to use any name which is a valid prop name. Translations containing markup will be parsed using a hidden <template> element. It creates a safe inert DocumentFragment with a hierarchy of text nodes and HTML elements. Any unknown elements (e.g. cancel in the example above) are parsed as HTMLUnknownElements. fluent-react then tries to match all elements found in the translation with props passed to the <Localized> component. If a match is found, the element passed as a prop is cloned with the translated text content taken from the DocumentFragment used as children.

  • Filter props with . (#139, #141)

    The <Localized> component now requires the attrs prop to set any localized attributes as props on the wrapped component. attrs should be an object with attribute names as keys and booleans as values.

    <Localized id="type-name" attrs={{placeholder: true}}>
        <input
            type="text"
            placeholder="Localizable placeholder"
            value={name}
            onChange={}
        />
    </Localized>

    By default, if attrs is not passed, no attributes will be set. This is a breaking change compared to the previous behavior: in fluent-react 0.4.1 and before <Localized> would set all attributes found in the translation.

Migrating from fluent-react 0.4.1 to 0.6.0

Add attrs to Localized.

If you're setting localized attributes as props of elements wrapped in <Localized>, in fluent-react 0.6.0 you'll need to also explicitly allow the props you're interested in using the attrs prop. This protects your components from accidentally gaining props they aren't expecting or from translations overwriting important props which shouldn't change.

// BEFORE (fluent-react 0.4.1)
<Localized id="type-name">
    <input
        type="text"
        placeholder="Localizable placeholder"
        value={name}
        onChange={}
    />
</Localized>
// AFTER (fluent-react 0.6.0)
<Localized id="type-name" attrs={{placeholder: true}}>
    <input
        type="text"
        placeholder="Localizable placeholder"
        value={name}
        onChange={}
    />
</Localized>
Don't pass elements as $arguments.

In fluent-react 0.4.1 it was possible to pass React elements as external arguments to localization via the $-prefixed props, just like you'd pass a number or a date. This was a bad localization practice because it resulted in the translation being split into multiple strings.

# Bad practice. This won't work in fluent-react 0.6.0.
send-comment-confirm = Send
send-comment-cancel = go back
send-comment = { $confirmButton } or { $cancelLink }.
// Bad practice. This won't work in fluent-react 0.6.0.
<Localized
    id="send-comment"
    $confirmButton={
        <Localized id="send-comment-confirm">
            <button onClick={sendComment}>{'Send'}</button>
        </Localized>
    }
    $cancelLink={
        <Localized id="send-comment-cancel">
            <Link to="/">{'go back'}</Link>
        </Localized>
    }
>
    <p>{'{ $confirmButton } or { $cancelLink}.'}</p>
</Localized>

fluent-react 0.6.0 removes support for this feature. It is no longer possible to pass React elements as $-prefixed arguments to translations. Please migrate your code to use markup in translations and pass React elements as props to <Localized>.

In the example above, change $confirmButton to confirm and $cancelLink to cancel. Note that you don't need to wrap the passed element in another <Localized> anymore. In particular, you don't need to assign a new message id for it. The text for this element will be taken from the send-comment message which can now include the markup for the button and the link.

send-comment = <confirm>Send</confirm> or <cancel>go back</cancel>.
// BEFORE (fluent-react 0.4.1)
<Localized
    id="send-comment"
    $confirmButton={
        <Localized id="send-comment-button">
            <button onClick={sendComment}>{'Send'}</button>
        </Localized>
    }
    $cancelLink={
        <Localized id="send-comment-cancel">
            <Link to="/">{'go back'}</Link>
        </Localized>
    }
>
    <p>{'{ $confirmButton } or { $cancelLink}.'}</p>
</Localized>
// AFTER (fluent-react 0.6.0)
<Localized
    id="send-comment"
    confirm={
        <button onClick={sendComment}></button>
    }
    cancel={
        <Link to="/"></Link>
    }
>
    <p>{'<confirm>Send</confirm> or <cancel>go back</cancel>.'}</p>
</Localized>
Use fluent 0.6.0+.

fluent-react 0.6.0 works best with fluent 0.6.0. It might still work with fluent 0.4.x but passing elements as $-prefixed arguments to translations will break your app. You might also run into other issues with translations with attributes and no values. Upgrading your code to fluent 0.6.0 and your localization files to Fluent Syntax 0.5 is the best way to avoid troubles.

fluent 0.6.0 (January 31, 2018)

31 Jan 19:31
Compare
Choose a tag to compare
Pre-release
  • 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:

    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.

    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.toString.

    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.

fluent-syntax 0.6.0 (January 31, 2018)

31 Jan 19:57
Compare
Choose a tag to compare
Pre-release
  • 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-syntax 0.6.x the new Syntax 0.5 is supported alongside the old Syntax 0.4. This should make migrations easier.

    FluentParser 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.

    FluentSerializer always serializes using the new Syntax 0.5.

  • Add AST.Placeable (#64)

    Added in Syntax Spec 0.4, AST.Placeable provides exact span data about the opening and closing brace of placeables.

  • Expose FluentSerializer.serializeExpression. (#134)

  • Serialize standalone comments with surrounding white-space.

  • Allow blank lines inside of messages. (#76)

  • Trim trailing newline from Comments. (#77)