Skip to content

Page-language i18n with Spanish support - #427

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

Page-language i18n with Spanish support#427
fernanDOTdo merged 2 commits into
mainfrom
feat/page-language-i18n

Conversation

@fernanDOTdo

Copy link
Copy Markdown
Member

Summary

Makes engrid-scripts language-aware, defaulting UI strings and field translations to the current page language (first 2 characters of pageJson.locale), with built-in en/es support.

New APIs

  • ENGrid.getPageLanguage() — returns the 2-letter page language ("es_US""es"), defaulting to "en" when pageJson/locale is missing.
  • ENGrid.t(key, replacements?) — dictionary lookup with page-language → English → key fallback and {placeholder} interpolation.
  • window.EngridI18n — new global to override/extend any dictionary string, merged key-by-key per language over the shipped I18nDefaults (same pattern as EngridTranslate).

Hardcoded English strings now translated (en/es)

Where String(s)
RememberMe checkbox label, "(clear autofill)" link, hover tooltip, iframe title
TranslateFields generic state labels ("State", "Province / State", "State/Region", "Province / Territory") and "Select…" placeholders; recipient block "To:" → "Para:" on es pages
A11y "There are X errors: …" announcement → "Hay X errores: …"

TranslateFields refactor

  • Page language is now the base translation layer, applied on page load and on every country change — even when the page has no country field.
  • Country translations remain the override layer: they win per field; a country with no defined translations leaves the locale base in place.
  • Added es supporter-field defaults (Nombre, Apellidos, Correo electrónico, Teléfono, Dirección, …) in TranslateOptionsDefaults.
  • Existing behavior is fully preserved for English pages and for the EngridTranslate global. RememberMe's rememberMeLabel/fieldClearLabel options still take precedence when explicitly set.

Verification

  • npm run build (tsc) — zero errors; dist/ rebuilt and included.
  • Runtime smoke test of getPageLanguage()/t() against the compiled source: es resolution, en fallback, unknown-language fallback, EngridI18n override (defaults not mutated), missing-key passthrough — all passed.

Documentation PR: engrid-docs (linked separately).

- ENGrid.getPageLanguage(): first 2 chars of pageJson.locale, lowercased (defaults to 'en')
- New i18n dictionary (interfaces/i18n-options.ts) with en/es UI strings,
  overridable via the window.EngridI18n global (merged per language, key by key)
- ENGrid.t(key, replacements): page language -> English -> key fallback, with {placeholder} interpolation
- RememberMe: label, clear-autofill link, tooltip and iframe title now come from the dictionary
  (explicit rememberMeLabel/fieldClearLabel options still win)
- TranslateFields: page language is the base translation layer on load and on every country
  change; country translations override it per field; added Spanish (es) supporter field defaults
- TranslateFields state labels and Select placeholders localized for es pages
- Recipient block follows the page language (es -> 'Para:') when no country rule matches
- A11y error summary announcement translated ('Hay {count} errores...')
- Blocker: apply the language layer before setStateField() so country-specific
  state labels ('Estado', 'Provincia', ...) win over the es base layer
- t(): interpolate via function replacement so $-sequences ($$, $&, ...) in
  user-facing text are inserted literally
- getPageLanguage(): tolerate window.pageJson being undefined/null (optional chaining)
- Recipient block: capture page-builder text in data-original so
  resetTranslatedFields() restores it (fixes stale 'À:' on FR->US), and apply
  the page-language 'To:' whenever the language dictionary defines the key
  (new ENGrid.hasI18nKey) instead of only for es
- Dictionary: restore curly quotes/apostrophes; consistent usted register in
  the es tooltip; es address2 -> 'Departamento/Piso'
- Document the country/language key convention on TranslateOptions
- Clone TranslateOptionsDefaults before merging EngridTranslate (no shared
  mutation on repeated instantiation)
- Pin typescript devDependency for reproducible builds
@fernanDOTdo
fernanDOTdo merged commit 480d7d1 into main Aug 28, 2026
2 checks passed
@fernanDOTdo
fernanDOTdo deleted the feat/page-language-i18n branch August 28, 2026 13:56
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