Skip to content

Support complex DOM trees in overlays #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stasm opened this issue Sep 27, 2018 · 3 comments
Open

Support complex DOM trees in overlays #288

stasm opened this issue Sep 27, 2018 · 3 comments

Comments

@stasm
Copy link
Contributor

stasm commented Sep 27, 2018

Sometimes, the line between UI localization and content localization is thin. A good example is netError.dtd in Gecko:

<!ENTITY dnsNotFound.longDesc1 "
<strong>If that address is correct, here are three other things you can try:</strong>
<ul>
  <li>Try again later.</li>
  <li>Check your network connection.</li>
  <li>If you are connected but behind a firewall, check that &brandShortName; has permission to access the Web.</li>
</ul>
">

Clearly in this case, the UI benefits from a more structured translation. In the past, we focused the design of Fluent on short messages with little structure and we avoided longer forms. With UIs like netError, we might want to find a middle-ground solution for conveniently localizing UI which features longer text and some structure.

The implementation of overlays in fluent-dom currently supports two groups of elements:

  1. elements named with the data-l10n-name attribute, as long as a corresponding element is present in the source, and
  2. a short list of inline text-level elements as defined by the HTML spec.

Furthermore the current implementation doesn't allow any nested elements. A <li> inside of a <p> wouldn't work even if these elements were allowed.

I'd like to start a discussion about what it would take to support UIs like netError.dtd. A few questions to get us started:

  1. Should we allow more elements by default, including block elements? Any translation would be free to use them even if they're not present in the source.
  2. How to handle errors in nesting order, if nested elements are allowed?
  3. Should we encourage static analysis tools to verify the structure of the DOM found in the translations by comparing it to the reference?
  4. Should text-level elements by exempt from this validation step?
@zbraniecki
Copy link
Collaborator

Thanks for kicking it off! My first thought is that we should limit such DOM Fragments to be white-listed by the developer. In other words, while I expect text level semantics to be allowed in every element, I expect such model to be only allowed when the developer specifically sets some attribute to say data-l10n-mode="dom-fragment" or something similar.

@Pike
Copy link
Contributor

Pike commented Sep 28, 2018

I agree that we should do this, and that we should make it opt-in.

  1. Should we allow more elements by default, including block elements? Any translation would be free to use them even if they're not present in the source.

I'd say no. As Zibi said, I'd make this opt-in.

  1. How to handle errors in nesting order, if nested elements are allowed?

Can we classify these errors?

Might also depend on whether opt-in is generic, or specific. Like, data-l10n-mode="fragment" vs data-l10n-fragments="p, ul>li", where the latter would be allow only a specific form of custom element hierarchy.

  1. Should we encourage static analysis tools to verify the structure of the DOM found in the translations by comparing it to the reference?

Yep, totally.

  1. Should text-level elements by exempt from this validation step?

I think so, yes.

@zbraniecki
Copy link
Collaborator

Example of a use case: https://bugzilla.mozilla.org/show_bug.cgi?id=1626064

nitn3lav added a commit to nitn3lav/fluent.js that referenced this issue Sep 18, 2023
    Because:

    * Sometimes, the line between UI localization and content localization
	  is thin. There are cases in which we should allow localizing longer,
	  structured text with nested overlays.

    This commit:

	* Adds a prop, nestedElems, to LocalizedProps and an arg, arg.nestedElems,
	  to Localized.getElement() that allows consumers to opt-in to
	  recursively parse nested elements in overlays. By default this is
	  disabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants