Open Bug 1287403 Opened 8 years ago Updated 8 years ago

Dispatch an event with details on localized nodes after a mutation

Categories

(L20n :: JS Library, defect)

defect
Not set
normal

Tracking

(Not tracked)

People

(Reporter: stas, Unassigned)

Details

Setting the data-l10n-id attribute trigger the MutationObserver's logic in a microtask.  It doesn't give the developer any way to schedule a callback when the mutation and the corresponding translation are complete.

One solution would be to dispatch an event on document with the list of affected nodes after every intercepted mutation.
Example use case?
The general use-case is when you set the data-l10n-id attribute and need to do something after the node has been translated by the Mutation Observer.  Sometimes it might be possible to react to the change of the data-l10n-id attribute itself, especially if the receiving code has access to the same Localization object.  In other cases the receiving code will want to work with the translated value.

Here's an example:  when a tab title changes, the tabbrowser.xml binding adjusts the value of the "crop" attribute:  center for URIs, end for everything else.  It then dispatches a TabAttrModified event [1] which can be intercepted by code elsewhere to run some logic, e.g. update previews of tabs in Ctrl-Tab UI [2].

[1] https://dxr.mozilla.org/mozilla-central/rev/4c05938a64a7fde3ac2d7f4493aee1c5f2ad8a0a/browser/base/content/tabbrowser.xml#1393
[2] https://dxr.mozilla.org/mozilla-central/rev/4c05938a64a7fde3ac2d7f4493aee1c5f2ad8a0a/browser/base/content/browser-ctrlTab.js#476

It might be possible to achieve the same with data-l10n-id and data-l10n-args.  As long as the intercepting code has access to the same Localization object I think things will work out.   I'd like to have this bug on file in case we run into a scenario where a different approach is required.

In general, tabbrowser.xml presents a few interesting challenges and I think it makes for a good testbed for l20n.js in Firefox.
You need to log in before you can comment on or make changes to this bug.