Bug 1453878 - Follow-up to fluent-dom to 0.2.0 landing. r=gandalf

MozReview-Commit-ID: D5jgJWzrDlX

--HG--
extra : rebase_source : 316dd7c060ddc0c023f601f8bb8ab91640c19c4e
This commit is contained in:
Zibi Braniecki 2018-04-12 22:20:05 -07:00
parent b8e12a1963
commit cc0beb7960
7 changed files with 23 additions and 21 deletions

View File

@ -39,7 +39,7 @@ add_task(async function() {
Assert.deepEqual(msg, { Assert.deepEqual(msg, {
value: null, value: null,
attrs: [ attributes: [
{name: "label", value: elem.getAttribute("label")} {name: "label", value: elem.getAttribute("label")}
] ]
}); });

View File

@ -350,12 +350,12 @@ function sanitizeTranslationForNodeLocalize(l10nItem, translation) {
return false; return false;
} }
if (translation.attrs) { if (translation.attributes) {
const explicitlyAllowed = l10nItem.l10nAttrs === null ? null : const explicitlyAllowed = l10nItem.l10nAttrs === null ? null :
l10nItem.l10nAttrs.split(",").map(i => i.trim()); l10nItem.l10nAttrs.split(",").map(i => i.trim());
for (const [j, {name}] of translation.attrs.entries()) { for (const [j, {name}] of translation.attributes.entries()) {
if (!isAttrNameLocalizable(name, l10nItem, explicitlyAllowed)) { if (!isAttrNameLocalizable(name, l10nItem, explicitlyAllowed)) {
translation.attrs.splice(j, 1); translation.attributes.splice(j, 1);
} }
} }
} }
@ -636,6 +636,8 @@ class DOMLocalization extends Localization {
// We will translate it below using JS DOM Overlays. // We will translate it below using JS DOM Overlays.
overlayTranslations[i] = translations[i]; overlayTranslations[i] = translations[i];
translations[i] = undefined; translations[i] = undefined;
} else {
translations[i].attrs = translations[i].attributes;
} }
} }

View File

@ -327,15 +327,15 @@ function messageFromContext(ctx, errors, id, args) {
const formatted = { const formatted = {
value: ctx.format(msg, args, errors), value: ctx.format(msg, args, errors),
attrs: null, attributes: null,
}; };
if (msg.attrs) { if (msg.attrs) {
formatted.attrs = []; formatted.attributes = [];
for (const name in msg.attrs) { for (const [name, attr] of Object.entries(msg.attrs)) {
const value = ctx.format(msg.attrs[name], args, errors); const value = ctx.format(attr, args, errors);
if (value !== null) { if (value !== null) {
formatted.attrs.push({ name, value }); formatted.attributes.push({name, value});
} }
} }
} }

View File

@ -15,7 +15,7 @@
async function* mockGenerateMessages(locales, resourceIds) { async function* mockGenerateMessages(locales, resourceIds) {
const mc = new MessageContext(locales); const mc = new MessageContext(locales);
mc.addMessages("title = <strong>Hello</strong> World"); mc.addMessages("title = <strong>Hello</strong> World");
mc.addMessages("title2 = This is <a>a link</a>!"); mc.addMessages(`title2 = This is <a data-l10n-name="link">a link</a>!`);
yield mc; yield mc;
} }
@ -50,7 +50,7 @@
<body> <body>
<p data-l10n-id="title" /> <p data-l10n-id="title" />
<p data-l10n-id="title2"> <p data-l10n-id="title2">
<a href="http://www.mozilla.org"></a> <a href="http://www.mozilla.org" data-l10n-name="link"></a>
</p> </p>
</body> </body>
</html> </html>

View File

@ -14,7 +14,7 @@
async function* mockGenerateMessages(locales, resourceIds) { async function* mockGenerateMessages(locales, resourceIds) {
const mc = new MessageContext(locales); const mc = new MessageContext(locales);
mc.addMessages("title = Visit <a>Mozilla</a> or <a>Firefox</a> website!"); mc.addMessages(`title = Visit <a data-l10n-name="mozilla-link">Mozilla</a> or <a data-l10n-name="firefox-link">Firefox</a> website!`);
yield mc; yield mc;
} }
@ -46,9 +46,9 @@
</head> </head>
<body> <body>
<p data-l10n-id="title"> <p data-l10n-id="title">
<a href="http://www.mozilla.org"></a> <a href="http://www.mozilla.org" data-l10n-name="mozilla-link"></a>
<a href="http://www.firefox.com"></a> <a href="http://www.firefox.com" data-l10n-name="firefox-link"></a>
<a href="http://www.w3.org"></a> <a href="http://www.w3.org" data-l10n-name="w3-link"></a>
</p> </p>
</body> </body>
</html> </html>

View File

@ -14,7 +14,7 @@
async function* mockGenerateMessages(locales, resourceIds) { async function* mockGenerateMessages(locales, resourceIds) {
const mc = new MessageContext(locales); const mc = new MessageContext(locales);
mc.addMessages("title = Visit <a>Mozilla</a> or <a>Firefox</a> website!"); mc.addMessages(`title = Visit <a data-l10n-name="mozilla-link">Mozilla</a> or <a data-l10n-name="firefox-link">Firefox</a> website!`);
yield mc; yield mc;
} }
@ -44,8 +44,8 @@
</head> </head>
<body> <body>
<p data-l10n-id="title"> <p data-l10n-id="title">
<a href="http://www.mozilla.org"></a> <a href="http://www.mozilla.org" data-l10n-name="mozilla-link"></a>
<a href="http://www.firefox.com"></a> <a href="http://www.firefox.com" data-l10n-name="firefox-link"></a>
</p> </p>
</body> </body>
</html> </html>

View File

@ -17,7 +17,7 @@
mc.addMessages(` mc.addMessages(`
key1 = Translation For Key 1 key1 = Translation For Key 1
key2 = Visit <a>this link<a/>. key2 = Visit <a data-l10n-name="link">this link<a/>.
`); `);
yield mc; yield mc;
} }
@ -53,11 +53,11 @@ key2 = Visit <a>this link<a/>.
<h2 id="elem2" data-l10n-id="key1"></h2> <h2 id="elem2" data-l10n-id="key1"></h2>
<p id="elem3" data-l10n-id="key2"> <p id="elem3" data-l10n-id="key2">
<a href="http://www.mozilla.org"></a> <a href="http://www.mozilla.org" data-l10n-name="link"></a>
</p> </p>
<p id="elem4" data-l10n-id="key2"> <p id="elem4" data-l10n-id="key2">
<a href="http://www.firefox.com"></a> <a href="http://www.firefox.com" data-l10n-name="link"></a>
</p> </p>
</body> </body>
</html> </html>