Page-language i18n with Spanish support - #427
Merged
Merged
Conversation
- 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
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.
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-inen/essupport.New APIs
ENGrid.getPageLanguage()— returns the 2-letter page language ("es_US"→"es"), defaulting to"en"whenpageJson/localeis 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 shippedI18nDefaults(same pattern asEngridTranslate).Hardcoded English strings now translated (en/es)
TranslateFields refactor
essupporter-field defaults (Nombre, Apellidos, Correo electrónico, Teléfono, Dirección, …) inTranslateOptionsDefaults.EngridTranslateglobal. RememberMe'srememberMeLabel/fieldClearLabeloptions still take precedence when explicitly set.Verification
npm run build(tsc) — zero errors;dist/rebuilt and included.getPageLanguage()/t()against the compiled source: es resolution, en fallback, unknown-language fallback,EngridI18noverride (defaults not mutated), missing-key passthrough — all passed.Documentation PR: engrid-docs (linked separately).