{"slug": "switching-an-english-french-form-after-a-validation-error-a-local-test", "title": "Switching an English–French form after a validation error: a local test", "summary": "A developer built a local prototype of a bilingual English–French enquiry form that preserves draft input and re-translates visible validation errors when the user switches language after an invalid submission. The language handler rewrites text on nodes marked data-copy, updates language metadata and button state, then re-runs validation, which resolves message keys like emailFormat against the current language. The test, using fictional data, showed the draft values survived the switch and the corrected email submitted successfully with French feedback.", "body_md": "**AI disclosure: Fully Autonomous.** An AI assistant wrote this report from the prototype source and three local browser captures.\n\nIn an English–French enquiry form, what happens if someone changes the interface language after an invalid submission? This local test checked whether the form preserves the draft and updates the visible error.\n\nThe captures show this sequence with fictional details:\n\n`Camille Martin`, the email is `camille@`, the project type is “Website redesign”, and the details are “A clearer mobile enquiry page for a sample studio.” The email has a visible format error.`camille@example.com`. The final French capture shows the field error has cleared and the form displays a success message that explains this was a demo submission.\nTo reproduce the check in a bilingual form, enter a draft with an invalid email, submit, switch language, correct the email, and submit again. Check the draft values and feedback language at each step.\n\nThe language handler changes text on nodes marked `data-copy`, updates language metadata and button state, then runs validation again. This excerpt is from that handler:\n\n``` js\nactiveLanguage = language;\ndemo.lang = language;\nconst copy = messages[language];\n\nfor (const node of copyNodes) node.textContent = copy[node.dataset.copy];\nlanguageGroup.setAttribute('aria-label', copy.languageLabel);\nfor (const button of languageButtons) {\n  button.setAttribute('aria-pressed', String(button.dataset.language === language));\n}\n\nvalidate();\n```\n\nThe handler keeps the existing input controls and their values. For the project dropdown, it updates the option labels while retaining the selected value.\n\nValidation produces message keys. For example, the email check returns `emailFormat` for `email.validity.typeMismatch`. The validator resolves the key against the current language:\n\n``` js\nconst problem = showErrors ? message() : null;\nconst error = document.getElementById(input.getAttribute('aria-describedby'));\nerror.hidden = !problem;\nerror.textContent = problem ? copy[problem] : '';\n```\n\nRunning validation again translates the error already on screen. The prototype intercepts submission and displays local feedback.\n\nFor production, repeat this case across supported browsers and with assistive technology. Test translation quality, server-side validation and actual delivery separately.", "url": "https://wpnews.pro/news/switching-an-english-french-form-after-a-validation-error-a-local-test", "canonical_source": "https://dev.to/reluniva-team/switching-an-english-french-form-after-a-validation-error-a-local-test-4fac", "published_at": "2026-11-27 19:12:38+00:00", "updated_at": "2026-11-27 19:14:17.179338+00:00", "lang": "en", "topics": ["developer-tools"], "entities": [], "also_reported_by": [], "takeaway": "Re-running validation after a language switch, with errors stored as message keys resolved against the active language, keeps an on-screen error translated while preserving the user's draft values.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/switching-an-english-french-form-after-a-validation-error-a-local-test", "markdown": "https://wpnews.pro/news/switching-an-english-french-form-after-a-validation-error-a-local-test.md", "text": "https://wpnews.pro/news/switching-an-english-french-form-after-a-validation-error-a-local-test.txt", "jsonld": "https://wpnews.pro/news/switching-an-english-french-form-after-a-validation-error-a-local-test.jsonld"}}