refactor code
This commit is contained in:
parent
740b3ea975
commit
af708b9043
@ -1,3 +1,8 @@
|
||||
{
|
||||
"extends": "next/core-web-vitals"
|
||||
"extends": "next/core-web-vitals",
|
||||
"rules": {
|
||||
"@next/next/no-img-element": "off",
|
||||
"react-hooks/exhaustive-deps": "off",
|
||||
"@next/next/no-html-link-for-pages": "off"
|
||||
}
|
||||
}
|
||||
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -34,3 +34,9 @@ yarn-error.log*
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
|
||||
.idea
|
||||
.vscode
|
||||
yarn.lock
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
|
@ -10,7 +10,7 @@
|
||||
"dependencies": {
|
||||
"@headlessui/react": "^1.7.18",
|
||||
"@heroicons/react": "^2.1.1",
|
||||
"@next/third-parties": "^14.1.3",
|
||||
"@next/third-parties": "^14.2.25",
|
||||
"@stripe/stripe-js": "^3.0.7",
|
||||
"@tailwindcss/typography": "^0.5.10",
|
||||
"ahooks": "^3.7.10",
|
||||
@ -18,9 +18,9 @@
|
||||
"clsx": "^2.1.0",
|
||||
"date-fns": "^3.3.1",
|
||||
"google-auth-library": "^9.6.3",
|
||||
"next": "14.1.3",
|
||||
"next": "14.2.25",
|
||||
"next-auth": "^4.24.6",
|
||||
"next-intl": "^3.9.2",
|
||||
"next-intl": "^3.26.0",
|
||||
"pg": "^8.11.3",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
@ -36,7 +36,7 @@
|
||||
"@types/react-dom": "^18",
|
||||
"autoprefixer": "^10.0.1",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "14.1.3",
|
||||
"eslint-config-next": "14.2.25",
|
||||
"postcss": "^8",
|
||||
"tailwindcss": "^3.3.0",
|
||||
"typescript": "^5"
|
||||
|
@ -1,25 +0,0 @@
|
||||
-- auto-generated definition
|
||||
create table works_translate_task
|
||||
(
|
||||
id bigint generated by default as identity
|
||||
primary key,
|
||||
created_at timestamp with time zone default now() not null,
|
||||
updated_at timestamp with time zone default now() not null,
|
||||
uid varchar,
|
||||
origin_language varchar,
|
||||
status varchar
|
||||
);
|
||||
|
||||
comment on table works_translate_task is 'works_translate_task';
|
||||
|
||||
comment on column works_translate_task.id is '自增id';
|
||||
|
||||
comment on column works_translate_task.created_at is '创建时间';
|
||||
|
||||
comment on column works_translate_task.updated_at is '更新时间';
|
||||
|
||||
comment on column works_translate_task.uid is 'uid';
|
||||
|
||||
comment on column works_translate_task.origin_language is 'origin_language';
|
||||
|
||||
comment on column works_translate_task.status is 'status: 0未翻译,1已翻译';
|
@ -1,78 +0,0 @@
|
||||
import {getDb} from "~/libs/db";
|
||||
import {locales} from "~/config";
|
||||
import {translateContent} from "~/servers/translate";
|
||||
|
||||
export const maxDuration = 300;
|
||||
|
||||
export async function GET() {
|
||||
const db = getDb();
|
||||
const timeFlag = 'workTranslate' + '-=->' + new Date().getTime();
|
||||
console.time(timeFlag);
|
||||
const results = await db.query('select * from works_translate_task where status=$1 order by created_at asc limit 3', [0]);
|
||||
const rows = results.rows;
|
||||
if (rows.length <= 0) {
|
||||
console.log('没有任务需要处理');
|
||||
console.timeEnd(timeFlag);
|
||||
return Response.json({message: '没有任务需要处理'});
|
||||
}
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const oneTask = rows[i];
|
||||
// 翻译为除了原始语言的其他语言,如果原始语言不在支持列表,就翻译为支持的十种语言
|
||||
const origin_language = oneTask.origin_language;
|
||||
const uid = oneTask.uid;
|
||||
|
||||
const needLanguage = getNeedTranslateLanguage(origin_language);
|
||||
|
||||
if (needLanguage.length <= 0) {
|
||||
// 更新状态为已翻译完成
|
||||
await db.query('update works_translate_task set status=$1 where uid=$2', [1, uid]);
|
||||
console.log('没有需要翻译的语言-=->', uid);
|
||||
console.timeEnd(timeFlag);
|
||||
return Response.json({message: '没有需要翻译的语言'});
|
||||
}
|
||||
|
||||
// 查出原始数据
|
||||
const resultsOrigin = await db.query('select * from works where uid=$1 and is_origin=$2 and is_delete=$3', [uid, true, false]);
|
||||
const rowsOrigin = resultsOrigin.rows;
|
||||
if (rowsOrigin.length <= 0) {
|
||||
console.log('没有原始数据-=->', uid);
|
||||
console.timeEnd(timeFlag);
|
||||
// 更新状态为已翻译完成
|
||||
await db.query('update works_translate_task set status=$1 where uid=$2', [1, uid]);
|
||||
return Response.json({message: '没有原始数据'});
|
||||
}
|
||||
const originData = rowsOrigin[0];
|
||||
if (originData.output_url == '') {
|
||||
// 如果原始数据的url还没生成,就不翻译了
|
||||
console.log('原始数据的url还没生成-=->', uid);
|
||||
console.timeEnd(timeFlag);
|
||||
return Response.json({message: '原始数据的url还没生成'});
|
||||
}
|
||||
const timeFlagCurrent = '翻译' + '-=->' + uid;
|
||||
console.time(timeFlagCurrent);
|
||||
for (let i = 0; i < needLanguage.length; i++) {
|
||||
const toLanguage = needLanguage[i];
|
||||
const translateText = await translateContent(originData.input_text, toLanguage);
|
||||
const sqlStr = 'insert into works(uid, input_text, output_url, is_public, status, user_id, revised_text, is_origin, origin_language, current_language) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)';
|
||||
const data = [uid, translateText, originData.output_url, originData.is_public, originData.status, originData.user_id, originData.revised_text, false, originData.origin_language, toLanguage];
|
||||
await db.query(sqlStr, data);
|
||||
}
|
||||
console.timeEnd(timeFlagCurrent);
|
||||
console.log('翻译完-=->', uid);
|
||||
// 更新状态为已翻译完成
|
||||
await db.query('update works_translate_task set status=$1 where uid=$2', [1, uid]);
|
||||
}
|
||||
console.timeEnd(timeFlag);
|
||||
return Response.json({message: '本次翻译任务翻译完'});
|
||||
}
|
||||
|
||||
function getNeedTranslateLanguage(origin_language: string) {
|
||||
const needTranslateLanguage = [];
|
||||
// 判断出需要翻译的语言,并调用翻译
|
||||
for (let i = 0; i < locales.length; i++) {
|
||||
if (origin_language != locales[i]) {
|
||||
needTranslateLanguage.push(locales[i]);
|
||||
}
|
||||
}
|
||||
return needTranslateLanguage;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { getUserById } from "~/servers/user";
|
||||
import { checkUserTimes, countDownUserTimes } from "~/servers/manageUserTimes";
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { getReplicateClient } from "~/libs/replicateClient";
|
||||
import { getInput } from "~/libs/replicate";
|
||||
import { getDb } from "~/libs/db";
|
||||
@ -8,20 +8,19 @@ import {getLanguage} from "~/servers/language";
|
||||
import { checkSubscribe } from "~/servers/subscribe";
|
||||
import { checkSensitiveInputText } from "~/servers/checkInput";
|
||||
|
||||
|
||||
export async function POST(req: Request, res: Response) {
|
||||
let json = await req.json();
|
||||
let textStr = json.textStr;
|
||||
let user_id = json.user_id;
|
||||
let is_public = json.is_public;
|
||||
|
||||
if (!user_id && process.env.NEXT_PUBLIC_CHECK_GOOGLE_LOGIN != '0') {
|
||||
if (!user_id && process.env.NEXT_PUBLIC_CHECK_GOOGLE_LOGIN != "0") {
|
||||
return Response.json({ msg: "Login to continue.", status: 601 });
|
||||
}
|
||||
|
||||
// 检查用户在数据库是否存在,不存在则返回需登录
|
||||
const resultsUser = await getUserById(user_id);
|
||||
if (resultsUser.email == '' && process.env.NEXT_PUBLIC_CHECK_GOOGLE_LOGIN != '0') {
|
||||
if (resultsUser.email == "" && process.env.NEXT_PUBLIC_CHECK_GOOGLE_LOGIN != "0") {
|
||||
return Response.json({ msg: "Login to continue.", status: 601 });
|
||||
}
|
||||
|
||||
@ -36,7 +35,7 @@ export async function POST(req: Request, res: Response) {
|
||||
|
||||
if (!checkSubscribeStatus) {
|
||||
const check = await checkUserTimes(user_id);
|
||||
if (!check && process.env.NEXT_PUBLIC_CHECK_AVAILABLE_TIME != '0') {
|
||||
if (!check && process.env.NEXT_PUBLIC_CHECK_AVAILABLE_TIME != "0") {
|
||||
return Response.json({ msg: "Pricing to continue.", status: 602 });
|
||||
}
|
||||
}
|
||||
@ -63,23 +62,30 @@ export async function POST(req: Request, res: Response) {
|
||||
input: input,
|
||||
webhook: `${process.env.REPLICATE_WEBHOOK}/api/generate/callByReplicate?uid=${uid}`,
|
||||
webhook_events_filter: ["completed"],
|
||||
})
|
||||
});
|
||||
|
||||
const db = getDb();
|
||||
// 创建新的数据
|
||||
await db.query('insert into works(uid, input_text, output_url, is_public, status, user_id, revised_text, is_origin, origin_language, current_language) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)',
|
||||
[uid, textStr, '', is_public, 0, user_id, input.prompt, true, origin_language, origin_language]);
|
||||
// 创建一条翻译任务
|
||||
await db.query('insert into works_translate_task(uid,origin_language,status) values($1,$2,$3)', [uid, origin_language, 0]);
|
||||
|
||||
await db.query("insert into works(uid, input_text, output_url, is_public, status, user_id, revised_text, is_origin, origin_language, current_language) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)", [
|
||||
uid,
|
||||
textStr,
|
||||
"",
|
||||
is_public,
|
||||
0,
|
||||
user_id,
|
||||
input.prompt,
|
||||
true,
|
||||
origin_language,
|
||||
origin_language,
|
||||
]);
|
||||
// 需要登录,且需要支付时,才操作该项
|
||||
if (process.env.NEXT_PUBLIC_CHECK_GOOGLE_LOGIN != '0' && process.env.NEXT_PUBLIC_CHECK_AVAILABLE_TIME != '0' && !checkSubscribeStatus) {
|
||||
if (process.env.NEXT_PUBLIC_CHECK_GOOGLE_LOGIN != "0" && process.env.NEXT_PUBLIC_CHECK_AVAILABLE_TIME != "0" && !checkSubscribeStatus) {
|
||||
// 减少用户次数
|
||||
await countDownUserTimes(user_id);
|
||||
}
|
||||
|
||||
const resultInfo = {
|
||||
uid: uid
|
||||
}
|
||||
uid: uid,
|
||||
};
|
||||
return Response.json(resultInfo);
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import clsx from 'clsx';
|
||||
import { Inter } from 'next/font/google';
|
||||
import { notFound } from 'next/navigation';
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
import { ReactNode } from 'react';
|
||||
import {locales} from '~/config';
|
||||
import { locales } from '~/i18n/config';
|
||||
import { CommonProvider } from '~/context/common-context';
|
||||
import { NextAuthProvider } from '~/context/next-auth-context';
|
||||
import {getAuthText, getCommonText, getMenuText, getPricingText} from "~/configs/languageText";
|
||||
import { getAuthText, getCommonText, getMenuText, getPricingText } from "~/i18n/languageText";
|
||||
|
||||
const inter = Inter({ subsets: ['latin'] });
|
||||
|
||||
@ -28,7 +28,7 @@ export default async function LocaleLayout({
|
||||
if (!locales.includes(locale as any)) notFound();
|
||||
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
const commonText = await getCommonText();
|
||||
const authText = await getAuthText();
|
||||
|
@ -1,13 +1,13 @@
|
||||
import PageComponent from "./PageComponent";
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
|
||||
import {
|
||||
getWorksText
|
||||
} from "~/configs/languageText";
|
||||
} from "~/i18n/languageText";
|
||||
|
||||
export default async function IndexPage({ params: { locale = '' } }) {
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
const worksText = await getWorksText();
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
import PageComponent from "./PageComponent";
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
|
||||
import {
|
||||
getIndexPageText,
|
||||
getQuestionText
|
||||
} from "~/configs/languageText";
|
||||
} from "~/i18n/languageText";
|
||||
import { getLatestPublicResultList } from "~/servers/works";
|
||||
|
||||
export const revalidate = 120;
|
||||
export default async function IndexPage({ params: { locale = '' }, searchParams: searchParams }) {
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
const indexText = await getIndexPageText();
|
||||
const questionText = await getQuestionText();
|
||||
|
@ -1,9 +1,9 @@
|
||||
import PageComponent from "./PageComponent";
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
|
||||
export default async function IndexPage({ params: { locale = '' } }) {
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
return (
|
||||
<PageComponent
|
||||
|
@ -1,13 +1,13 @@
|
||||
import PageComponent from "./PageComponent";
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
|
||||
import {
|
||||
getPrivacyPolicyText
|
||||
} from "~/configs/languageText";
|
||||
} from "~/i18n/languageText";
|
||||
|
||||
export default async function IndexPage({ params: { locale = '' } }) {
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
const privacyPolicyText = await getPrivacyPolicyText();
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import PageComponent from "./PageComponent";
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import {getSearchText} from "~/configs/languageText";
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
import { getSearchText } from "~/i18n/languageText";
|
||||
import { getLatestPublicResultList } from "~/servers/works";
|
||||
import { getCountSticker } from "~/servers/keyValue";
|
||||
import { searchByWords, addSearchLog } from "~/servers/search";
|
||||
@ -9,7 +9,7 @@ export const revalidate = 0;
|
||||
|
||||
export default async function SearchPage({ params: { locale = '' }, searchParams: { sticker = '' } }) {
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
|
||||
const countSticker = await getCountSticker();
|
||||
|
@ -1,9 +1,9 @@
|
||||
import PageComponent from "./PageComponent";
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
|
||||
import {
|
||||
getDetailText,
|
||||
} from "~/configs/languageText";
|
||||
} from "~/i18n/languageText";
|
||||
import { getSimilarList, getWorkDetailByUid } from "~/servers/works";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
@ -13,7 +13,7 @@ export const dynamic = 'error';
|
||||
|
||||
export default async function IndexPage({ params: { locale = '', uid = '' } }) {
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
const workDetail = await getWorkDetailByUid(locale, uid);
|
||||
if (workDetail.status == 404) {
|
||||
|
@ -1,9 +1,9 @@
|
||||
import PageComponent from "./PageComponent";
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
|
||||
import {
|
||||
getExploreText,
|
||||
} from "~/configs/languageText";
|
||||
} from "~/i18n/languageText";
|
||||
import { getPagination, getPublicResultList } from "~/servers/works";
|
||||
import { notFound } from "next/navigation";
|
||||
import { getCountSticker } from "~/servers/keyValue";
|
||||
@ -13,7 +13,7 @@ export const dynamic = "force-static";
|
||||
|
||||
export default async function IndexPage({ params: { locale = '', page = 2 } }) {
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
const countSticker = await getCountSticker();
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import PageComponent from "./PageComponent";
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
|
||||
import {
|
||||
getExploreText,
|
||||
} from "~/configs/languageText";
|
||||
} from "~/i18n/languageText";
|
||||
import { getPagination, getPublicResultList } from "~/servers/works";
|
||||
import { getCountSticker } from "~/servers/keyValue";
|
||||
|
||||
@ -11,7 +11,7 @@ export const revalidate = 300;
|
||||
|
||||
export default async function IndexPage({ params: { locale = '' } }) {
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
const countSticker = await getCountSticker();
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
import PageComponent from "./PageComponent";
|
||||
import {unstable_setRequestLocale} from 'next-intl/server';
|
||||
import { setRequestLocale } from 'next-intl/server';
|
||||
|
||||
import {
|
||||
getTermsOfServiceText
|
||||
} from "~/configs/languageText";
|
||||
} from "~/i18n/languageText";
|
||||
|
||||
export default async function IndexPage({ params: { locale = '' } }) {
|
||||
// Enable static rendering
|
||||
unstable_setRequestLocale(locale);
|
||||
setRequestLocale(locale);
|
||||
|
||||
const termsOfServiceText = await getTermsOfServiceText();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {languages} from "~/config";
|
||||
import { languages } from "~/i18n/config";
|
||||
|
||||
const HeadInfo = ({
|
||||
locale,
|
||||
|
@ -7,7 +7,7 @@ import {Fragment} from 'react'
|
||||
import { Menu, Transition } from '@headlessui/react'
|
||||
import { ChevronDownIcon } from '@heroicons/react/20/solid'
|
||||
import Link from "next/link";
|
||||
import {languages} from "~/config";
|
||||
import { languages } from "~/i18n/config";
|
||||
import { useCommonContext } from '~/context/common-context'
|
||||
import LoadingModal from "./LoadingModal";
|
||||
import GeneratingModal from "~/components/GeneratingModal";
|
||||
|
@ -1,34 +0,0 @@
|
||||
import {Pathnames} from 'next-intl/navigation';
|
||||
|
||||
export const locales = ['en', 'zh'] as const;
|
||||
|
||||
export const languages = [
|
||||
{
|
||||
code: "en-US",
|
||||
lang: "en",
|
||||
language: "English",
|
||||
},
|
||||
{
|
||||
code: "zh-CN",
|
||||
lang: "zh",
|
||||
language: "简体中文",
|
||||
},
|
||||
]
|
||||
|
||||
export const pathnames = {
|
||||
'/': '/',
|
||||
} satisfies Pathnames<typeof locales>;
|
||||
|
||||
// Use the default: `always`,设置为 as-needed可不显示默认路由
|
||||
export const localePrefix = 'as-needed';
|
||||
|
||||
export type AppPathnames = keyof typeof pathnames;
|
||||
|
||||
|
||||
export const getLanguageByLang = (lang) => {
|
||||
for (let i = 0; i < languages.length; i++) {
|
||||
if (lang == languages[i].lang) {
|
||||
return languages[i];
|
||||
}
|
||||
}
|
||||
}
|
10
src/i18n.ts
10
src/i18n.ts
@ -1,10 +0,0 @@
|
||||
import {getRequestConfig} from 'next-intl/server';
|
||||
|
||||
export default getRequestConfig(async ({locale}) => ({
|
||||
messages: (
|
||||
await (locale === 'en'
|
||||
? // When using Turbopack, this will enable HMR for `default`
|
||||
import('../messages/en.json')
|
||||
: import(`../messages/${locale}.json`))
|
||||
).default
|
||||
}));
|
22
src/i18n/config.ts
Normal file
22
src/i18n/config.ts
Normal file
@ -0,0 +1,22 @@
|
||||
export const locales = ["en", "zh"] as const;
|
||||
|
||||
export const languages = [
|
||||
{
|
||||
code: "en-US",
|
||||
lang: "en",
|
||||
language: "English",
|
||||
},
|
||||
{
|
||||
code: "zh-CN",
|
||||
lang: "zh",
|
||||
language: "简体中文",
|
||||
},
|
||||
];
|
||||
|
||||
export const getLanguageByLang = (lang) => {
|
||||
for (let i = 0; i < languages.length; i++) {
|
||||
if (lang == languages[i].lang) {
|
||||
return languages[i];
|
||||
}
|
||||
}
|
||||
};
|
4
src/i18n/navigation.ts
Normal file
4
src/i18n/navigation.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { createNavigation } from "next-intl/navigation";
|
||||
import { routing } from "./routing";
|
||||
|
||||
export const { Link, redirect, usePathname, useRouter, getPathname } = createNavigation(routing);
|
17
src/i18n/request.ts
Normal file
17
src/i18n/request.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { getRequestConfig } from "next-intl/server";
|
||||
import { routing } from "./routing";
|
||||
|
||||
export default getRequestConfig(async ({ requestLocale }) => {
|
||||
// This typically corresponds to the `[locale]` segment
|
||||
let locale = await requestLocale;
|
||||
|
||||
// Ensure that a valid locale is used
|
||||
if (!locale || !routing.locales.includes(locale as any)) {
|
||||
locale = routing.defaultLocale;
|
||||
}
|
||||
|
||||
return {
|
||||
locale,
|
||||
messages: (await import(`../../messages/${locale}.json`)).default,
|
||||
};
|
||||
});
|
13
src/i18n/routing.ts
Normal file
13
src/i18n/routing.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { defineRouting } from "next-intl/routing";
|
||||
import { locales } from "./config";
|
||||
|
||||
export const routing = defineRouting({
|
||||
// A list of all locales that are supported
|
||||
locales: locales,
|
||||
// Used when no locale matches
|
||||
defaultLocale: "en",
|
||||
// Use the default: `always`,设置为 as-needed可不显示默认路由
|
||||
localePrefix: "as-needed",
|
||||
localeDetection: false,
|
||||
alternateLinks: false,
|
||||
});
|
@ -1,26 +1,19 @@
|
||||
import createMiddleware from 'next-intl/middleware';
|
||||
import {pathnames, locales, localePrefix} from './config';
|
||||
import createMiddleware from "next-intl/middleware";
|
||||
import { routing } from "./i18n/routing";
|
||||
|
||||
export default createMiddleware({
|
||||
defaultLocale: 'en',
|
||||
locales,
|
||||
pathnames,
|
||||
localePrefix,
|
||||
localeDetection: false,
|
||||
alternateLinks: false
|
||||
});
|
||||
export default createMiddleware(routing);
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
// Enable a redirect to a matching locale at the root
|
||||
'/',
|
||||
"/",
|
||||
|
||||
// Set a cookie to remember the previous locale for
|
||||
// all requests that have a locale prefix
|
||||
'/(en|zh)/:path*',
|
||||
"/(en|zh)/:path*",
|
||||
|
||||
// Enable redirects that add missing locales
|
||||
// (e.g. `/pathnames` -> `/en/pathnames`)
|
||||
'/((?!_next|_vercel|.*\\..*).*)'
|
||||
]
|
||||
"/((?!_next|_vercel|.*\\..*).*)",
|
||||
],
|
||||
};
|
||||
|
@ -1,9 +0,0 @@
|
||||
import {createLocalizedPathnamesNavigation} from 'next-intl/navigation';
|
||||
import {locales, pathnames, localePrefix} from './config';
|
||||
|
||||
export const {Link, redirect, usePathname, useRouter} =
|
||||
createLocalizedPathnamesNavigation({
|
||||
locales,
|
||||
pathnames,
|
||||
localePrefix
|
||||
});
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"crons": [
|
||||
{
|
||||
"path": "/api/cron/workTranslate",
|
||||
"schedule": "*/1 * * * *"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user