localizeHTML function exported

Last updated: 2026-03-01T23:25:47.122Z

Metrics

LOC: 25 Complexity: 5 Params: 1

Signature

localizeHTML(root: Document | Element = document): : void

Summary

Processes all elements with i18n data attributes in root and replaces their content/attributes with the localized strings. Supported attributes: data-i18n → sets element.textContent data-i18n-title → sets element.title data-i18n-placeholder → sets (element as HTMLInputElement).placeholder data-i18n-aria-label → sets element.ariaLabel

Source Code

export function localizeHTML(root: Document | Element = document): void {
  root.querySelectorAll<HTMLElement>("[data-i18n]").forEach((el) => {
    const msg = t(el.dataset.i18n!);
    if (msg) el.textContent = msg;
  });

  root.querySelectorAll<HTMLElement>("[data-i18n-title]").forEach((el) => {
    const msg = t(el.dataset.i18nTitle!);
    if (msg) el.title = msg;
  });

  root
    .querySelectorAll<
      HTMLInputElement | HTMLTextAreaElement
    >("[data-i18n-placeholder]")
    .forEach((el) => {
      const msg = t((el as HTMLElement).dataset.i18nPlaceholder!);
      if (msg) el.placeholder = msg;
    });

  root.querySelectorAll<HTMLElement>("[data-i18n-aria-label]").forEach((el) => {
    const msg = t(el.dataset.i18nAriaLabel!);
    if (msg) el.setAttribute("aria-label", msg);
  });
}

Dependencies (Outgoing)

graph LR localizeHTML["localizeHTML"] t["t"] localizeHTML -->|calls| t style localizeHTML fill:#dbeafe,stroke:#2563eb,stroke-width:2px click localizeHTML "ea912f73a0316785.html" click t "8e8864a3c5cfd1e1.html"
TargetType
t calls

Impact (Incoming)

graph LR localizeHTML["localizeHTML"] main["main"] debounce["debounce"] main -->|uses| localizeHTML debounce -->|uses| localizeHTML style localizeHTML fill:#dbeafe,stroke:#2563eb,stroke-width:2px click localizeHTML "ea912f73a0316785.html" click main "14348c66c1e5604a.html" click debounce "806c18ff0675c421.html"
SourceType
main uses
debounce uses