diff --git a/scripts/localize-html.js b/scripts/localize-html.js
index 625a45a..a5d5a14 100644
--- a/scripts/localize-html.js
+++ b/scripts/localize-html.js
@@ -30,8 +30,10 @@ function tokens(source) {
if (start < 0) break;
const end = tagEnd(source, start);
if (end < 0) break;
- result.push({ tag: false, value: source.slice(cursor, start) });
- result.push({ tag: true, value: source.slice(start, end + 1) });
+ result.push(
+ { tag: false, value: source.slice(cursor, start) },
+ { tag: true, value: source.slice(start, end + 1) }
+ );
cursor = end + 1;
}
result.push({ tag: false, value: source.slice(cursor) });
@@ -96,8 +98,9 @@ function localizeAttributes(tag, fields, translate) {
export function localizeHtml(source, translate) {
const parts = tokens(source);
const result = [];
- for (let index = 0; index < parts.length; index += 1) {
- const part = parts[index];
+ let skipText = false;
+ for (const [index, part] of parts.entries()) {
+ if (skipText) { skipText = false; continue; }
if (!part.tag) { result.push(part.value); continue; }
const fields = attributes(part.value);
result.push(localizeAttributes(part.value, fields, translate));
@@ -106,7 +109,7 @@ export function localizeHtml(source, translate) {
const closing = parts[index + 2];
if (key && !text?.tag && closing?.value.startsWith('')) {
result.push(escapeText(translate(key)));
- index += 1;
+ skipText = true;
}
}
return result.join('');