Middle
Tell me how multilingualism was implemented in the project (4 languages, Next.js)
sobes.tech AI
Answer from AI
In a Next.js project supporting 4 languages, multilingualism is usually implemented through Next.js's built-in i18n support or using libraries such as next-i18next.
Main points:
- In
next.config.js, an array of supported locales is specified, for example:locales: ['en', 'ru', 'de', 'fr']. - Next.js automatically handles routing with language prefixes (
/en,/ru, etc.). - Texts are stored in separate JSON files for each language, which are loaded on the server or client side.
- To switch languages, a component or function changes the current locale.
Example configuration:
module.exports = {
i18n: {
locales: ['en', 'ru', 'de', 'fr'],
defaultLocale: 'en',
},
}
This allows automatic handling of page and route localization, as well as optimizing the loading of necessary language resources.