Course contentsShow
← Web Development
Lesson 2505 of 2,98245. InternationalizationFree lesson

User Override and Preference UI

Build interface controls that let users manually select and change their preferred locale.

User Override and Preference UI

You'll learn: How to build interface controls that let users manually select and change their preferred locale, giving them direct control over their language experience.

Why Let Users Choose?

Even with perfect automatic locale detection, users sometimes want to override what the system guessed. Maybe they're browsing in a Spanish-speaking country but prefer English, or they're learning a new language and want immersion. Just like a thermostat lets you override the automatic temperature setting, a preference UI puts users in control of their linguistic environment.

Building the Control

The simplest approach is a language selector—typically a dropdown or menu in your site's header or settings panel:

<select id="locale-selector" aria-label="Choose language">
  <option value="en-US">English (US)</option>
  <option value="es-ES">Español (España)</option>
  <option value="fr-FR">Français (France)</option>
  <option value="de-DE">Deutsch (Deutschland)</option>
</select>

<script>
  const selector = document.getElementById('locale-selector');
  
  // Set current locale
  selector.value = localStorage.getItem('userLocale') || navigator.language;
  
  selector.addEventListener('change', (e) => {
    const chosenLocale = e.target.value;
    localStorage.setItem('userLocale', chosenLocale);
    
    // Reload page or update content
    window.location.reload();
  });
</script>

This control lets users explicitly choose, persists their choice in localStorage (building on lesson 2501), and triggers a reload to apply the change.

Design Considerations

Place the selector prominently—often in the header or footer. Use native language names ("Español" not "Spanish") so users can find their language. Consider a globe icon (🌐) as a universal indicator.

Key Takeaway: A well-designed locale preference UI empowers users to override automatic detection, ensuring they always see content in their chosen language—persist their choice and make the control easy to find.