How do you serve content in multiple languages?
HTMLThe short answer
Use a combination of the HTTP Accept-Language header (to detect the user's preferred language), URL-based language routing (like /en/ or /es/), translation files with a library like i18next, and proper HTML attributes (lang, hreflang). Let users switch languages manually — never rely only on automatic detection.
Detecting the user's language
From the HTTP header:
// Server-side (Express)app.get('/', (req, res) => { const language = req.headers['accept-language']; // "en-US,en;q=0.9,es;q=0.8" const preferred = language.split(',')[0].split('-')[0]; // "en" res.redirect(`/${preferred}/`);});From the browser:
const language = navigator.language; // "en-US"const languages = navigator.languages; // ["en-US", "en", "es"]Translation files
Store translations as key-value pairs:
// en.json{ "greeting": "Hello", "cart": "Shopping Cart", "checkout": "Checkout" }// es.json{ "greeting": "Hola", "cart": "Carrito de Compras", "checkout": "Pagar" }Use a library like i18next to load and display them:
const { t } = useTranslation();return <h1>{t('greeting')}</h1>; // "Hello" or "Hola"Important HTTP headers
Content-Language — tells the browser what language the response is in:
Content-Language: eshreflang — tells search engines about alternate language versions (covered in detail in the multilingual site concerns question).
Best practices
- Always provide a manual language switcher — do not rely only on auto-detection
- Handle pluralization rules (different per language)
- Test with actual translations, not just English in both slots
Interview Tip
Cover: language detection (Accept-Language header), URL structure (subdirectories), translation files, and SEO (hreflang). The most important point is to always let users switch manually — automatic detection is a starting point, not the final answer.
Why interviewers ask this
This tests practical knowledge of internationalization. Companies with global users need developers who can build multilingual experiences correctly, from server-side detection to client-side rendering to SEO.