next-i18next.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const isDev = process.env.NODE_ENV === 'development';
  2. // biome-ignore lint/style/useNodejsImportProtocol: ignore
  3. const path = require('path');
  4. const { AllLang } = require('@growi/core');
  5. const { isServer } = require('@growi/core/dist/utils');
  6. const { defaultLang } = require('./i18next.config');
  7. const HMRPlugin = isDev ? require('i18next-hmr/plugin').HMRPlugin : undefined;
  8. /** @type {import('next-i18next').UserConfig} */
  9. module.exports = {
  10. ...require('./i18next.config').initOptions,
  11. i18n: {
  12. defaultLocale: defaultLang.toString(),
  13. locales: AllLang,
  14. },
  15. localePath: path.resolve('./public/static/locales'),
  16. serializeConfig: false,
  17. // eslint-disable-next-line no-nested-ternary
  18. use: isDev
  19. ? isServer()
  20. ? [new HMRPlugin({ webpack: { server: true } })]
  21. : [
  22. require('i18next-chained-backend').default,
  23. new HMRPlugin({ webpack: { client: true } }),
  24. ]
  25. : [],
  26. backend: {
  27. backends: isServer()
  28. ? []
  29. : [
  30. require('i18next-localstorage-backend').default,
  31. require('i18next-http-backend').default,
  32. ],
  33. backendOptions: [
  34. // options for i18next-localstorage-backend
  35. { expirationTime: isDev ? 0 : 24 * 60 * 60 * 1000 }, // 1 day in production
  36. // options for i18next-http-backend
  37. { loadPath: '/static/locales/{{lng}}/{{ns}}.json' },
  38. ],
  39. },
  40. };