next-i18next.config.js 1.3 KB

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