next-i18next.config.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. 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. };