...
The next-i18next
...
config file (next-i18next
...
.config.js
)
To configure next-i18next, a config file is required. This tells next-i18next
what your defaultLocale
and other locales are, so that it can preload translations on the server. More information about the config file can be found in the next-i18next docs.
...
Code Block |
---|
module.exports = {
i18n: {
// all the locales supported in the application
locales: ['en-GB', 'en-US'],
// the default locale to be used when visiting
// a non-localized route (e.g. `/about`)
defaultLocale: 'en-GB',
},
fallbackLng: 'en-GB',
ns: ['common', 'application', 'validation'],
defaultNS: 'application',
fallbackNS: 'common',
// configure the path for localization (i18n) files based on the environment
// if the code is running on server side it will use ./public/locales
// if the code is running on client side it will use /locales
localePath:
typeof window === 'undefined'
? require('path').resolve('./public/locales')
: '/locales',
} |
The next.config.js file
Modify your next.config.js
file, by passing the i18n
object into your next.config.js
file, to enable localised URL routing:
next.config.js
Code Block |
---|
const { i18n } = require('./next-i18next.config') module.exports = { i18n, } |