From a3ee08ad4d26735fccaffb536df82c0819492a67 Mon Sep 17 00:00:00 2001 From: Florian Zumpe Date: Fri, 2 Oct 2026 08:59:53 +0200 Subject: [PATCH] minor optimization --- scripts/localize-html.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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('