Translate field placeholders on non-English pages - #428
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #427 (reported during testing on a Spanish page: labels translated, placeholders stayed English).
Root cause
Two layers, both fixed:
translateField's placeholder guard compared rawlabel.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.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 newplaceholders.*i18n keys (en/es: "Street Address" → "Calle y número", "Phone Number (Optional)" → "Teléfono (opcional)", etc.). Client strings set via thePlaceholdersoption are never translated — overrides always win.Verification (jsdom, against compiled output)
Placeholdersoverride on an es page keeps the client's stringnpm run build(tsc) clean;dist/includedDocs updated in 4site-interactive-studios/engrid-docs#19.