Accessibility and localization
Make the same learning and product flow usable with keyboards, assistive technology and different languages.
What you will be able to do
- Implement semantic controls and announced feedback.
- Preserve focus through navigation and asynchronous updates.
- Use explicit locale and time-zone inputs to avoid unstable rendering.
- Design dictionary fallback and text expansion deliberately.
Accessibility is interaction correctness
A form is not complete if only a mouse user can discover its error. A modal is not complete if focus escapes behind it or never returns. Treat keyboard access, names, roles, focus and announcements as acceptance criteria alongside network success. Start with native links, buttons, labels, fieldsets and headings because their default behavior already carries useful semantics.
The course uses glass surfaces as presentation, but the readable surface must maintain sufficient contrast in both themes. Blur cannot be required to understand text. Test forced colors, reduced motion, zoom and a narrow viewport. An attractive card that clips its text at 200 percent zoom or hides the focused button behind a sticky header violates the interaction contract.
Connect the error to the control
A visible label should identify each input. Associate help and error text through stable IDs, and expose invalid state only when validation establishes a problem. A summary can help locate several errors, while inline messages explain the exact correction. Avoid announcing the same message through several live regions at once.
The small component below demonstrates native semantics for one field. Its parent supplies a real action result and controls when focus should move to a summary or first invalid field. Success feedback normally should not steal focus. Pending labels should communicate work and remain understandable when heard without the surrounding visual layout.
Client module
"use client";
import { useId } from "react";
export default function NameField({ error = "" }: { error?: string }) {
const id = useId();
return <div>
<label htmlFor={id}>Product name</label>
<input id={id} name="name" required aria-invalid={Boolean(error)}
aria-describedby={error ? id + "-error" : undefined} />
{error ? <p id={id + "-error"}>{error}</p> : null}
</div>;
}Locale is part of the rendering input
A translated route can use an app/[lang] structure and a server-loaded dictionary. Validate the language against supported values before loading a file. Do not concatenate arbitrary input into an import path. Keep the selected locale consistent between the server snapshot and the first browser render, including number, date and plural formatting.
Time zones matter independently of language. A server in UTC and a browser in India can format the same timestamp differently if defaults are implicit. Pass an intentional locale and timeZone or show a deterministic initial representation before a deliberate client-only enhancement. This is a data-contract problem as well as a hydration problem.
Design for expansion and missing translations
Labels often become longer after translation. Use flexible layouts, allow wrapping and avoid fixed heights that crop sentences. Right-to-left layouts require logical spacing and direction-aware icons where meaning changes. Do not translate opaque identifiers, code or URLs merely because the surrounding interface is translated.
Define dictionary fallback before shipping partial localization. A missing key can fall back to the default language; an unknown key should remain diagnosable. The exercise resolves requested strings with a deterministic fallback. In the real page, test Tamil and English text, mixed script content, long translated buttons and a keyboard-only save flow with an error.
Misconceptions to replace
Compare the tempting shortcut with the model you can verify in code.
- CLAIM TO CHALLENGEA placeholder is a sufficient label.
- A more accurate model
Use a visible programmatic label and associate help/error text through stable IDs.
- How to check it
WAI form notifications and the NameField example.
- CLAIM TO CHALLENGEAn accessibility scanner proves the whole user flow is accessible.
- A more accurate model
Automated checks need keyboard, zoom, focus and relevant assistive-technology verification.
- How to check it
Run the complete dashboard save flow without a mouse.
Mistakes to catch in your own code
- Using a placeholder as the only label.
- Assuming an automated scan proves keyboard usability.
- Formatting dates with different implicit server and browser time zones.
- Using fixed-height cards that clip translated text.
Write it by hand
JavaScript logic playground
Resolve dictionary keys with fallback
Implement solve(input). This sandbox runs the lesson's logic with FrontendX's isolated code runner. Next.js server behavior is verified in the project lab below.
- Input contains locale, fallbackLocale, dictionaries and keys. Dictionaries map locale names to string values by key.
- For each requested key, prefer a nonempty trimmed string in the selected dictionary, then the fallback dictionary.
- If neither exists, use [key]. Return an array of {key,text,from}, with from equal to selected locale, fallback locale or missing.
Tab moves to the next control. Use spaces to indent and return your answer from solve. Console output is not retained.
Inspect 3 test cases
- Use translated and fallback text
Input
{ "locale": "ta", "fallbackLocale": "en", "dictionaries": { "ta": { "save": "சேமி" }, "en": { "save": "Save", "cancel": "Cancel" } }, "keys": [ "save", "cancel" ] }Expected
[ { "key": "save", "text": "சேமி", "from": "ta" }, { "key": "cancel", "text": "Cancel", "from": "en" } ] - Expose a missing key
Input
{ "locale": "fr", "fallbackLocale": "en", "dictionaries": { "en": {} }, "keys": [ "save" ] }Expected
[ { "key": "save", "text": "[save]", "from": "missing" } ] - Treat blank strings as missing
Input
{ "locale": "ta", "fallbackLocale": "en", "dictionaries": { "ta": { "save": " " }, "en": { "save": "Save" } }, "keys": [ "save" ] }Expected
[ { "key": "save", "text": "Save", "from": "en" } ]
Reveal the worked solution and reasoning
function solve(input) {
const selected = input.dictionaries[input.locale] || {};
const fallback = input.dictionaries[input.fallbackLocale] || {};
return input.keys.map(key => {
const local = Object.prototype.hasOwnProperty.call(selected, key) ? selected[key] : null;
if (typeof local === "string" && local.trim()) return { key, text: local, from: input.locale };
const backup = Object.prototype.hasOwnProperty.call(fallback, key) ? fallback[key] : null;
if (typeof backup === "string" && backup.trim()) return { key, text: backup, from: input.fallbackLocale };
return { key, text: "[" + key + "]", from: "missing" };
});
}A fixed fallback makes the rendered text predictable.
Own-property checks prevent inherited object properties from becoming accidental translation values.
The kata resolves text only; plural rules, rich messages and direction handling need additional explicit contracts.
Verify it in a real Next.js application
Next.js application lab
Audit the existing form and extend it for localization
Open the local application route /dashboard after starting the workbench. Follow the experiment and collect the evidence described below.
Make the change
- Sign in and complete the existing task form using Tab, Shift+Tab and Enter. Inspect the label, aria-describedby, aria-invalid, pending button and status message in components/task-form.tsx.
- Submit three spaces to trigger server validation and verify that the message is understandable, related to the input and leaves the draft editable. Test the same workflow at narrow widths and 200 percent zoom.
- Navigate from the catalogue into its existing native product dialog, use Escape to close it, and inspect focus restoration. Record any keyboard or assistive-technology issues instead of treating a native element as a completed audit.
- Implementation extension: introduce locale routing or dictionary selection and longer English/Tamil form messages. The shipped app uses English and has no translated dictionary or locale-routing layer.
- Implementation extension: make server and first-client date/number formatting agree on locale and time zone. Use the existing /hydration ISO snapshot as a reference, then test your own translated presentation after hydration.
Check the behavior
- Every tested control has an accessible name and visible keyboard focus, and the feedback can be understood without color.
- Validation preserves the existing draft, and the keyboard user can reach the recovery control.
- The product-dialog check records Escape behavior and focus movement in an actual browser.
- The localization extension does not introduce page-level horizontal scrolling or an initial server/client formatting mismatch. Translation coverage is not claimed for the current English fixture.
Review the application reasoning
The kata proves dictionary-fallback logic. Keyboard behavior, contrast, zoom, screen-reader announcements and translated layout require separate interface observations.
Open the project files and run instructions
A complete App Router application with catalogue routing, cart state, a task dashboard, practice sessions, tenant checks, cached data, hydration repairs, and HTTP streaming. Next.js 16.4.6 and React 19.3.0 are pinned in the project.
The playground opens a new editable copy. A local Node.js 22.14+ installation also runs the project. Use the local production build when measuring caching, streaming, or deployment behavior.
cd nextjs-interview-lab
npm ci
npm run dev
# In a second terminal
npm test
# Stop dev, then verify the production application
npm run build
npm start
# In a second terminal, install the test browser once
npx playwright install chromium
npm run test:e2eOpen http://localhost:3003. The project includes a credential-free practice account selector and a single-process file store. Those choices make experiments reproducible; the security and deployment lessons show what a production system needs.
Explain it in an interview
Give your answer aloud before opening the explanation. Then answer the follow-ups using your implementation as evidence.
01What makes a server-validated form accessible?
It has programmatic labels, field-specific error associations, useful focus management and a clear status for pending or successful work. The same validation result must be understandable without relying on color.
I test with the keyboard and inspect the accessibility tree, then perform relevant screen-reader checks. A successful POST alone does not prove the interaction is usable.
Follow-up questions
- Should success always move focus?
- How do you avoid repeated error announcements?
- WAI form notificationsOfficial documentation
- Forms with Server ActionsOfficial documentation
02How can localization cause a hydration mismatch?
If the server and browser choose different locale or time-zone defaults, the first rendered text can differ. A timestamp may become a different date or use a different number format.
I make the formatting inputs explicit and keep the first snapshot consistent. If personalization requires browser-only information, I add it after hydration with a deliberate transition.
Follow-up questions
- Is language the same as time zone?
- When is suppressHydrationWarning justified?
- InternationalizationOfficial documentation
- Hydration error diagnosisOfficial documentation
- React hydrateRootOfficial documentation
03What should be checked in a glass-themed interface?
Text and control contrast must remain sufficient over the actual backgrounds, focus must be visible and information must not depend on blur, transparency or animation.
I check both themes, zoom, narrow widths, reduced motion and keyboard order. Decorative effects should degrade without removing readable content or state.
Follow-up questions
- What happens if backdrop-filter is unavailable?
- How do you test a long translated heading?
- WAI form notificationsOfficial documentation
04Why load the dictionary from a validated locale?
A route parameter is untrusted. Mapping it through a fixed set of supported dictionaries prevents arbitrary file selection and makes fallback behavior explicit.
Server loading also keeps unused language data out of the client bundle when the UI does not need every dictionary. I still preserve the selected locale across navigation and metadata.
Follow-up questions
- What if a translation key is missing?
- How would you add right-to-left support?
- InternationalizationOfficial documentation
- Server and client boundaryOfficial documentation
Check your understanding
Answer these without reopening the worked examples. The feedback explains the reasoning and the misconception behind each choice.
Your checkpoint
Loading your local progress.
Sources and further reading
- WAI form notificationsOfficial documentation
- InternationalizationOfficial documentation
- Hydration error diagnosisOfficial documentation
- React hydrateRootOfficial documentation
- Forms with Server ActionsOfficial documentation