next-i18next.config.js 1.3 KB

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