-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext-i18next.config.js
33 lines (28 loc) · 964 Bytes
/
next-i18next.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const invariant = require('tiny-invariant');
const path = require('path');
invariant(
process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE,
'NEXT_PUBLIC_DEFAULT_LANGUAGE is required, but not set, check your .env file'
);
invariant(
process.env.NEXT_PUBLIC_AVAILABLE_LANGUAGES,
'NEXT_PUBLIC_AVAILABLE_LANGUAGES is required, but not set, check your .env file'
);
const isMultilangEnable =
process.env.NEXT_PUBLIC_ENABLE_MULTI_LANG === 'true' &&
!!process.env.NEXT_PUBLIC_AVAILABLE_LANGUAGES;
function generateLocales() {
if (isMultilangEnable) {
return process.env.NEXT_PUBLIC_AVAILABLE_LANGUAGES.split(',');
}
return [process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE];
}
module.exports = {
i18n: {
defaultLocale: process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE ?? "en",
locales: generateLocales(),
localeDetection: isMultilangEnable,
},
localePath: path.resolve('./public/locales'),
reloadOnPrerender: process.env.NODE_ENV === 'development',
};