What is the main purpose of a language switching UI in a web app?
It allows users to change the website's language easily, improving accessibility and user experience for people who speak different languages.
Click to reveal answer
intermediate
In Next.js, which feature helps manage multiple languages for a website?
Next.js supports internationalized routing, which lets you define locales and automatically handle language-specific URLs.
Click to reveal answer
beginner
Why should language switch buttons use semantic HTML and ARIA labels?
Semantic HTML and ARIA labels make the buttons accessible to screen readers and assistive technologies, helping users with disabilities navigate the site.
Click to reveal answer
intermediate
How can you remember the user's language choice in a Next.js app?
You can store the language choice in cookies or localStorage, so the app remembers the preference on future visits.
Click to reveal answer
beginner
What is a common UI pattern for language switching on mobile devices?
A dropdown menu or a modal with language options is common, ensuring it is easy to tap and navigate on small screens.
Click to reveal answer
Which Next.js feature helps create URLs for different languages automatically?
Hint: useState returns array destructured into state and setter [OK]
Common Mistakes:
Not destructuring the array returned by useState
Missing initial state value
Incorrect assignment order
3. Given this Next.js component snippet: <pre>const LanguageSwitcher = () => {
const [lang, setLang] = useState('en');
return (
<button onClick={() => setLang('fr')} aria-label="Switch to French">FR</button>
);
};
What will be the value of lang after clicking the button once?
medium
A. null
B. 'en'
C. undefined
D. 'fr'
Solution
Step 1: Understand initial state
The state variable lang starts as 'en'.
Step 2: Analyze button click effect
Clicking the button calls setLang('fr'), updating lang to 'fr'.
Final Answer:
'fr' -> Option D
Quick Check:
Click sets lang to 'fr' [OK]
Hint: Click triggers setLang with new language [OK]
Common Mistakes:
Thinking state stays the same after click
Confusing initial value with updated value
4. Consider this Next.js language switcher code: <pre>const LanguageSwitcher = () => {
const [lang, setLang] = useState('en');
return (
<button onClick={() => setLang('es')}>Switch to Spanish</button>
);
};
Why might this code cause an accessibility issue?
medium
A. The state variable is not initialized
B. The button lacks an aria-label describing its purpose
C. The onClick handler syntax is incorrect
D. The component does not import React
Solution
Step 1: Check accessibility features
The button has no aria-label or descriptive text for screen readers.
Step 2: Evaluate other options
State is initialized, onClick syntax is correct, React import is assumed; only missing aria-label is an accessibility issue.
Final Answer:
The button lacks an aria-label describing its purpose -> Option B
Quick Check:
Missing aria-label = accessibility problem [OK]
Hint: Always add aria-label for buttons with unclear text [OK]
Common Mistakes:
Ignoring accessibility attributes
Assuming syntax errors without checking
Overlooking React import necessity
5. You want to build a language switcher in Next.js that updates the URL locale and changes the displayed language without a full page reload. Which approach is best?
hard
A. Reload the page manually after setting a cookie for language
B. Use window.location.href to change URL and reload page
C. Use Next.js <Link> with locale prop and React state to track language
D. Store language in localStorage and ignore URL changes
Solution
Step 1: Understand Next.js locale routing
Next.js supports locale routing with to change language without full reload.
Step 2: Combine URL update and React state
Using <Link> with locale prop updates URL and React state tracks current language for UI updates.
Step 3: Evaluate other options
Reloading page or using window.location causes full reload, losing SPA benefits. Ignoring URL breaks routing consistency.
Final Answer:
Use Next.js <Link> with locale prop and React state to track language -> Option C
Quick Check:
Next.js locale routing + state = smooth language switch [OK]
Hint: Use Next.js for smooth language changes [OK]
Common Mistakes:
Reloading page loses SPA benefits
Ignoring URL locale causes routing issues
Using localStorage alone misses URL sync
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.