You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
974 B

4 weeks ago
  1. /** @type {import('next-i18next').UserConfig} */
  2. const invariant = require('tiny-invariant');
  3. const path = require('path');
  4. invariant(
  5. process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE,
  6. 'NEXT_PUBLIC_DEFAULT_LANGUAGE is required, but not set, check your .env file'
  7. );
  8. invariant(
  9. process.env.NEXT_PUBLIC_AVAILABLE_LANGUAGES,
  10. 'NEXT_PUBLIC_AVAILABLE_LANGUAGES is required, but not set, check your .env file'
  11. );
  12. const isMultilangEnable =
  13. process.env.NEXT_PUBLIC_ENABLE_MULTI_LANG === 'true' &&
  14. !!process.env.NEXT_PUBLIC_AVAILABLE_LANGUAGES;
  15. function generateLocales() {
  16. if (isMultilangEnable) {
  17. return process.env.NEXT_PUBLIC_AVAILABLE_LANGUAGES.split(',');
  18. }
  19. return [process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE];
  20. }
  21. module.exports = {
  22. i18n: {
  23. defaultLocale: process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE ?? "en",
  24. locales: generateLocales(),
  25. },
  26. localePath: path.resolve('./public/locales'),
  27. reloadOnPrerender: process.env.NODE_ENV === 'development',
  28. };