Skip to content

Translate field placeholders on non-English pages - #428

Merged
fernanDOTdo merged 2 commits into
mainfrom
feat/page-language-i18n
Aug 28, 2026
Merged

Translate field placeholders on non-English pages#428
fernanDOTdo merged 2 commits into
mainfrom
feat/page-language-i18n

Conversation

@fernanDOTdo

Copy link
Copy Markdown
Member

Follow-up to #427 (reported during testing on a Spanish page: labels translated, placeholders stayed English).

Root cause

Two layers, both fixed:

  1. translateField's placeholder guard compared raw label.innerHTML === input.placeholder. EN templates put whitespace/indentation inside labels, so visually identical pairs ("First Name" / "First Name") failed the comparison — the label translated, the placeholder didn't.
  2. Distinct label-variant placeholders like "Street Address" (under an "Address" label) come from InputPlaceholders' own hardcoded English defaults, which ran untranslated before TranslateFields.

Changes

  • translate-fields.ts — the guard now compares normalized visible text (textContent, whitespace-collapsed, trailing required-marker * stripped). Placeholders that mirror the label translate; placeholders with their own hint text are still left untouched.
  • input-placeholders.ts — built-in default placeholder strings follow the page language via new placeholders.* i18n keys (en/es: "Street Address" → "Calle y número", "Phone Number (Optional)" → "Teléfono (opcional)", etc.). Client strings set via the Placeholders option are never translated — overrides always win.

Verification (jsdom, against compiled output)

  • es page: labels + placeholders translate ("Nombre", "Correo electrónico", "Calle y número", "Ciudad") — including whitespace-padded and required-marker labels
  • en page: everything untouched (control)
  • Client Placeholders override on an es page keeps the client's string
  • Full review matrix from Page-language i18n with Spanish support #427 re-run: state labels, recipient block, country layering — all still pass
  • npm run build (tsc) clean; dist/ included

Docs updated in 4site-interactive-studios/engrid-docs#19.

- translateField: compare normalized visible label text (textContent,
  whitespace-collapsed, required-marker asterisk stripped) instead of raw
  innerHTML when deciding to translate a placeholder — template whitespace
  no longer leaves placeholders in English while labels translate
- InputPlaceholders: built-in default placeholder strings now follow the
  page language via new placeholders.* i18n keys (en/es). Client-provided
  Placeholders options always win and are never translated
- Normalize in the correct order (collapse whitespace -> trim -> strip
  trailing '*') so labels like 'First Name *\n' match their placeholders;
  strip the marker from the placeholder text symmetrically
- Add es translation for phoneNumber2 '000-000-0000 (Optional)'
- Comment on defaultPlaceholders: i18n-mapped strings live in
  i18n-options.ts
@fernanDOTdo
fernanDOTdo merged commit ee91dbc into main Aug 28, 2026
2 checks passed
@fernanDOTdo
fernanDOTdo deleted the feat/page-language-i18n branch August 28, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant