Skip to content

Decouple message attributes from DOM attributes #437

Open
@stasm

Description

@stasm

The current design of DOM and React bindings tends to create a tight coupling in the long term between Fluent messages and the UI widgets they localize. The attributes found on compound messages are used to localize DOM attributes and React props with the same names.

The tight coupling contributes to the accruing of technical debt. It discourages from making changes to the source element to avoid breaking its translations or the need to migrate them to the new structure.

To remedy this situation, I wonder if it would be a good idea to change the bindings to expose in the source a way to map DOM attributes to Fluent message attributes (or the other way around).

For example, the following message could then be used to localize a number of different elements, either at the same time, or as a function of time.

toolbar-back =
    .label = Back
    .accesskey = B
    .tooltip = Go back one page

Then, using @fluent/dom:

<menuitem data-l10n-id="navbar-menu-back"
    data-l10n-attrs="aria-label:label accesskey tooltiptext:tooltip">
<description data-l10n-id="navbar-tooltip-back"
    data-l10n-attrs="value:tooltip">
<toolbarbutton data-l10n-id="toolbar-button-back"
    data-l10n-attrs="label">

Or using @fluent/react:

<Localized id="navbar-menu-back" attrs={{
    ariaLabel: "label",
    accesskey: "accesskey", // or true, since the names match and because
                            // we already use true in attrs right now
    tooltiptext: "tooltip"
}}>...</Localized>

Compound messages adapted to this usage pattern would likely only use attributes because the message value would not be "mappable"

# Can't map the value to a source DOM attribute
toolbar-back = Back
    .accesskey = B
# Can map "label" to a source DOM attribute
toolbar-back =
    .label = Back
    .accesskey = B

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions