React / Next.js

Next.js Internationalization

next-intl, locale routing, translations, date/time formatting, RTL support, dynamic locale switching

20 interview questionsยท
Senior
1

What is the main role of the middleware.ts file in a Next.js application with next-intl?

Answer

The next-intl middleware automatically detects the user's locale (via Accept-Language header, cookies, or URL) and redirects to the appropriate URL with the locale prefix. It runs before each request and handles locale negotiation without additional code in components. It's the required entry point to enable i18n routing in Next.js App Router.

2

In next-intl, where should translation files be placed for an optimal project structure?

Answer

Translation files are placed in messages/[locale].json at the project root (e.g., messages/fr.json, messages/en.json). This convention facilitates translation discovery and allows next-intl to load them automatically via the i18n configuration. Some projects also use messages/[locale]/ with separate files per namespace for better organization.

3

What is the main difference between useTranslations and getTranslations in next-intl?

Answer

useTranslations is a synchronous React hook for Client Components, while getTranslations is an async function for Server Components. getTranslations allows fetching translations server-side without sending JavaScript to the client, improving performance. useTranslations is necessary for interactive components that require the use client directive.

4

How to configure supported locales in next-intl?

5

What is the syntax for using variables in a next-intl translation?

+17 interview questions

Master React / Next.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free