Yuki Takei 3 лет назад
Родитель
Сommit
ea6f231b17
2 измененных файлов с 43 добавлено и 35 удалено
  1. 24 23
      apps/app/config/next-i18next.config.js
  2. 19 12
      apps/app/src/utils/next.config.utils.js

+ 24 - 23
apps/app/config/next-i18next.config.js

@@ -1,28 +1,29 @@
-import path from 'path';
+const path = require('path');
 
-import { isServer, AllLang, Lang } from '@growi/core';
-import I18nextChainedBackend from 'i18next-chained-backend';
-import I18NextHttpBackend from 'i18next-http-backend';
-import I18NextLocalStorageBackend from 'i18next-localstorage-backend';
+const { isServer, AllLang, Lang } = require('@growi/core');
+const I18nextChainedBackend = require('i18next-chained-backend').default;
+const I18NextHttpBackend = require('i18next-http-backend');
+const I18NextLocalStorageBackend = require('i18next-localstorage-backend').default;
 
 const isDev = process.env.NODE_ENV === 'development';
 
-export const defaultLang = Lang.en_US;
-export const i18n = {
-  defaultLocale: defaultLang,
-  locales: AllLang,
-};
-export const defaultNS = 'translation';
-export const localePath = path.resolve('./public/static/locales');
-
-export const serializeConfig = false;
-export const use = isServer() ? [] : [I18nextChainedBackend];
-export const backend = {
-  backends: isServer() ? [] : [I18NextLocalStorageBackend, I18NextHttpBackend],
-  backendOptions: [
-    // options for i18next-localstorage-backend
-    { expirationTime: isDev ? 0 : 24 * 60 * 60 * 1000 }, // 1 day in production
-    // options for i18next-http-backend
-    { loadPath: '/static/locales/{{lng}}/{{ns}}.json' },
-  ],
+module.exports = {
+  defaultLang: Lang.en_US,
+  i18n: {
+    defaultLocale: Lang.en_US,
+    locales: AllLang,
+  },
+  defaultNS: 'translation',
+  localePath: path.resolve('./public/static/locales'),
+  serializeConfig: false,
+  use: isServer() ? [] : [I18nextChainedBackend],
+  backend: {
+    backends: isServer() ? [] : [I18NextLocalStorageBackend, I18NextHttpBackend],
+    backendOptions: [
+      // options for i18next-localstorage-backend
+      { expirationTime: isDev ? 0 : 24 * 60 * 60 * 1000 }, // 1 day in production
+      // options for i18next-http-backend
+      { loadPath: '/static/locales/{{lng}}/{{ns}}.json' },
+    ],
+  },
 };

+ 19 - 12
apps/app/src/utils/next.config.utils.js

@@ -1,19 +1,23 @@
 // workaround by https://github.com/martpie/next-transpile-modules/issues/143#issuecomment-817467144
 
-import fs from 'fs';
-import path from 'path';
+const fs = require('fs');
+const path = require('path');
 
 const nodeModulesPath = path.resolve(__dirname, '../../../../node_modules');
 
-type Opts = {
-  ignorePackageNames: string[],
-}
+/**
+ * @typedef { { ignorePackageNames: string[] } } Opts
+ */
 
-const defaultOpts: Opts = { ignorePackageNames: [] };
+/** @type {Opts} */
+const defaultOpts = { ignorePackageNames: [] };
 
-// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-export const listScopedPackages = (scopes: string[], opts = defaultOpts) => {
-  const scopedPackages: string[] = [];
+/**
+ * @param scopes {string[]}
+ */
+exports.listScopedPackages = (scopes, opts = defaultOpts) => {
+  /** @type {string[]} */
+  const scopedPackages = [];
 
   fs.readdirSync(nodeModulesPath)
     .filter(name => scopes.includes(name))
@@ -36,9 +40,12 @@ export const listScopedPackages = (scopes: string[], opts = defaultOpts) => {
   return scopedPackages;
 };
 
-// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-export const listPrefixedPackages = (prefixes: string[], opts = defaultOpts) => {
-  const prefixedPackages: string[] = [];
+/**
+ * @param prefixes {string[]}
+ */
+exports.listPrefixedPackages = (prefixes, opts = defaultOpts) => {
+  /** @type {string[]} */
+  const prefixedPackages = [];
 
   fs.readdirSync(nodeModulesPath)
     .filter(name => prefixes.some(prefix => name.startsWith(prefix)))