ryoji-s 2 лет назад
Родитель
Сommit
002041b943

+ 1 - 1
apps/app/src/pages/utils/commons.ts

@@ -8,7 +8,6 @@ import type { SSRConfig, UserConfig } from 'next-i18next';
 
 import * as nextI18NextConfig from '^/config/next-i18next.config';
 
-import { detectLocaleFromBrowserAcceptLanguage } from '~/client/util/locale-utils';
 import { type SupportedActionType } from '~/interfaces/activity';
 import type { CrowiRequest } from '~/interfaces/crowi-request';
 import type { ISidebarConfig } from '~/interfaces/sidebar-config';
@@ -18,6 +17,7 @@ import type { UserUISettingsDocument } from '~/server/models/user-ui-settings';
 import {
   useCurrentProductNavWidth, useCurrentSidebarContents, usePreferCollapsedMode,
 } from '~/stores/ui';
+import { detectLocaleFromBrowserAcceptLanguage } from '~/utils/locale-utils';
 
 export type CommonProps = {
   namespacesRequired: string[], // i18next

+ 16 - 9
apps/app/src/server/routes/apiv3/page/create-page.ts

@@ -1,7 +1,5 @@
-import { allOrigin } from '@growi/core';
-import type {
-  IPage, IUser, IUserHasId,
-} from '@growi/core';
+import type { IPage, IUser, IUserHasId } from '@growi/core';
+import { allOrigin, Lang } from '@growi/core';
 import { ErrorV3 } from '@growi/core/dist/models';
 import { isCreatablePage, isUserPage, isUsersHomepage } from '@growi/core/dist/utils/page-path-utils';
 import { attachTitleHeader, normalizePath } from '@growi/core/dist/utils/path-utils';
@@ -22,13 +20,13 @@ import {
 import type { PageDocument, PageModel } from '~/server/models/page';
 import PageTagRelation from '~/server/models/page-tag-relation';
 import { configManager } from '~/server/service/config-manager';
+import { detectLocaleFromBrowserAcceptLanguage } from '~/utils/locale-utils';
 import loggerFactory from '~/utils/logger';
 
 import { apiV3FormValidator } from '../../../middlewares/apiv3-form-validator';
 import { excludeReadOnlyUser } from '../../../middlewares/exclude-read-only-user';
 import type { ApiV3Response } from '../interfaces/apiv3-response';
 
-
 const logger = loggerFactory('growi:routes:apiv3:page:create-page');
 
 
@@ -42,9 +40,13 @@ async function generateUntitledPath(parentPath: string, basePathname: string, in
   return path;
 }
 
-async function determinePath(_parentPath?: string, _path?: string, optionalParentPath?: string): Promise<string> {
-  // TODO: i18n
-  const basePathname = 'Untitled';
+async function determinePath(locale: Lang, _parentPath?: string, _path?: string, optionalParentPath?: string): Promise<string> {
+  const basePathnames = {
+    [Lang.en_US]: 'Untitled',
+    [Lang.ja_JP]: '無題のページ',
+    [Lang.zh_CN]: 'Untitled',
+  };
+  const basePathname = basePathnames[locale] || 'Untitled';
 
   if (_path != null) {
     const path = normalizePath(_path);
@@ -211,7 +213,12 @@ export const createPageHandlersFactory: CreatePageHandlersFactory = (crowi) => {
       let pathToCreate: string;
       try {
         const { path, parentPath, optionalParentPath } = req.body;
-        pathToCreate = await determinePath(parentPath, path, optionalParentPath);
+
+        // determine language
+        const locale = req.user == null ? detectLocaleFromBrowserAcceptLanguage(req.headers)
+          : (req.user.lang ?? configManager.getConfig('crowi', 'app:globalLang') as Lang ?? Lang.en_US);
+
+        pathToCreate = await determinePath(locale, parentPath, path, optionalParentPath);
       }
       catch (err) {
         return res.apiv3Err(new ErrorV3(err.toString(), 'could_not_create_page'));