TinyWebEx / Localizer

A tiny library that translates your HTML file with the WebExtension translation system.
https://tinywebex.github.io/Localizer/
MIT License
4 stars 1 forks source link

HTML template elements are not localized #4

Open tdulcet opened 4 months ago

tdulcet commented 4 months ago

HTML template elements are not localized as expected:

<template>
    <span data-i18n="__MSG_example__">Please translate me!</span>
</template>

The issue is that they are not found by document.querySelectorAll: https://github.com/TinyWebEx/Localizer/blob/f6da4ca47caf7d4c93725363f2bbc994f1d655fd/Localizer.js#L283-L286

This affects my Thunderbird Send add-on, which uses an HTML template element in the popup. See https://github.com/tdulcet/Thunderbird-Send/pull/14.

CC: @DenB10

rugk commented 4 months ago

Hmm interesting, it seems this is a feature of the template tag. Does it work if you set shadowrootmode to open?

tdulcet commented 4 months ago

Does it work if you set shadowrootmode to open?

No, setting it "open" breaks the template element and produces an exception: TypeError: can't access property "content", template is null. The solution might be to iterate over any template elements separately and then perform the query on each one.