Full answer
Internationalization has three parts: translating text, formatting values for a locale, and adapting layout.
For text, replace hard-coded strings with message keys. A provider holds the current locale and messages, and a t('greeting', { name }) function returns the translated string with placeholders filled. Libraries add loading of locale files, fallbacks, and ICU message syntax, which can express plurals and gender in one message. react-i18next and react-intl are the common choices, and frameworks such as Next.js have their own routing support for locales.
Plurals differ by language. English has one and other, but Arabic and Polish have several forms. Do not write count === 1 ? 'item' : 'items'. Use Intl.PluralRules or the library's plural syntax, so each locale picks the right form.
Formatting values uses the Intl objects, which are built into browsers: Intl.NumberFormat for numbers and currency, Intl.DateTimeFormat for dates and times, and Intl.RelativeTimeFormat for "2 days ago". The same number prints as 1,234.5 in English (US) and 1.234,5 in German.
Other rules: never build sentences from pieces, because word order differs by language. Keep the whole sentence as one message with placeholders. Set <html lang> and dir for accessibility and right-to-left languages such as Arabic and Hebrew, and prefer logical CSS properties (margin-inline-start) over left and right. Allow for text that is 30 percent longer. Load only the active locale to keep bundles small.
The example uses a small provider with Intl for plurals, numbers and dates, no library.
import { createContext, useContext, useState } from 'react';
const messages = {
en: { greeting: 'Hello, {name}', items: { one: '{count} course', other: '{count} courses' } },
hi: { greeting: 'Namaste, {name}', items: { one: '{count} paathyakram', other: '{count} paathyakram' } },
};
const I18nContext = createContext(null);
function I18nProvider({ children }) {
const [locale, setLocale] = useState('en');
function t(key, values = {}) {
const entry = messages[locale][key];
const template =
typeof entry === 'string' ? entry : entry[new Intl.PluralRules(locale).select(values.count)];
return template.replace(/\{(\w+)\}/g, (_, name) => values[name]);
}
return <I18nContext value={{ locale, setLocale, t }}>{children}</I18nContext>;
}
function useI18n() {
return useContext(I18nContext);
}
function Summary() {
const { locale, setLocale, t } = useI18n();
const price = new Intl.NumberFormat(locale === 'hi' ? 'en-IN' : 'en-US', {
style: 'currency',
currency: locale === 'hi' ? 'INR' : 'USD',
}).format(1234.5);
const date = new Intl.DateTimeFormat(locale, { dateStyle: 'long', timeZone: 'UTC' }).format(new Date(Date.UTC(2026, 11, 4)));
return (
<div lang={locale}>
<p>{t('greeting', { name: 'Asha' })}</p>
<p>{t('items', { count: 1 })}</p>
<p>{t('items', { count: 3 })}</p>
<p>
{price} on {date}
</p>
<button onClick={() => setLocale('hi')}>Switch to Hindi</button>
</div>
);
}
export default function App() {
return (
<I18nProvider>
<Summary />
</I18nProvider>
);
}The result before the click is English with a US dollar price. After the click the locale is hi, so the greeting, the currency and the date format change. Rendered result: before <div lang="en"><p>Hello, Asha</p><p>1 course</p><p>3 courses</p><p>$1,234.50 on December 4, 2026</p><button>Switch to Hindi</button></div> after <div lang="hi"><p>Namaste, Asha</p><p>1 paathyakram</p><p>3 paathyakram</p><p>₹1,234.50 on 4 दिसंबर 2026</p><button>Switch to Hindi</button></div>
Key points
- Replace strings with keys and look them up through a provider or a library.
- Use Intl.PluralRules or ICU syntax for plurals. Do not hard-code singular and plural.
- Use Intl.NumberFormat and Intl.DateTimeFormat for values.
- Never concatenate sentence fragments.
- Set lang and dir, use logical CSS properties and plan for longer text.
Common mistakes
- Building sentences by joining translated fragments.
- Using count === 1 for plurals.
- Formatting dates with manual string slicing instead of Intl.
- Forgetting lang and dir on the document.
- Hard-coding left and right in CSS for a layout that must flip.
Follow-ups
- How would you lazy-load only the active locale file?
- How do you handle right-to-left languages?
- What does ICU message syntax let you express that plain templates cannot?
Tips
- Mention Intl APIs first. They remove a lot of library need.
- Use plurals as the example of why concatenation fails.
- Raise layout issues (expansion, RTL) to show you think beyond strings.