|
|
@@ -1,4 +1,4 @@
|
|
|
-import { allOrigin } from '@growi/core';
|
|
|
+import { allOrigin, Lang } from '@growi/core';
|
|
|
import type {
|
|
|
IPage, IUser, IUserHasId,
|
|
|
} from '@growi/core';
|
|
|
@@ -9,6 +9,7 @@ import type { Request, RequestHandler } from 'express';
|
|
|
import type { ValidationChain } from 'express-validator';
|
|
|
import { body } from 'express-validator';
|
|
|
import mongoose from 'mongoose';
|
|
|
+import { i18n } from 'next-i18next';
|
|
|
|
|
|
import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
|
|
|
import type { IApiv3PageCreateParams } from '~/interfaces/apiv3';
|
|
|
@@ -22,6 +23,7 @@ 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';
|
|
|
@@ -42,8 +44,16 @@ async function generateUntitledPath(parentPath: string, basePathname: string, in
|
|
|
return path;
|
|
|
}
|
|
|
|
|
|
-async function determinePath(t: any, _parentPath?: string, _path?: string, optionalParentPath?: string): Promise<string> {
|
|
|
- const basePathname = t('create_page.untitled');
|
|
|
+async function determinePath(req: any, _parentPath?: string, _path?: string, optionalParentPath?: string): Promise<string> {
|
|
|
+ const user = req.user;
|
|
|
+ const headers = req.headers;
|
|
|
+
|
|
|
+ // determine language
|
|
|
+ const locale = user == null ? detectLocaleFromBrowserAcceptLanguage(headers)
|
|
|
+ : (user.lang ?? configManager.getConfig('crowi', 'app:globalLang') as Lang ?? Lang.en_US);
|
|
|
+
|
|
|
+ const t = i18n?.getFixedT(locale);
|
|
|
+ const basePathname = t?.('create_page.untitled') || 'Untitled';
|
|
|
|
|
|
if (_path != null) {
|
|
|
const path = normalizePath(_path);
|
|
|
@@ -214,7 +224,7 @@ export const createPageHandlersFactory: CreatePageHandlersFactory = (crowi) => {
|
|
|
let pathToCreate: string;
|
|
|
try {
|
|
|
const { path, parentPath, optionalParentPath } = req.body;
|
|
|
- pathToCreate = await determinePath(req.t, parentPath, path, optionalParentPath);
|
|
|
+ pathToCreate = await determinePath(req, parentPath, path, optionalParentPath);
|
|
|
}
|
|
|
catch (err) {
|
|
|
return res.apiv3Err(new ErrorV3(err.toString(), 'could_not_create_page'));
|