Skip to content

Commit 6bb04e9

Browse files
committed
feat: remove routing i18n, use env instead
1 parent e20fbb3 commit 6bb04e9

File tree

19 files changed

+73
-188
lines changed

19 files changed

+73
-188
lines changed

apps/docs/.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# https://fumadocs.dev/docs/mdx/async
22
MDX_ASYNC=
3-
EN_DOMAIN=nextjs.im
4-
ZH_HANS_DOMAIN=zh-hans.nextjs.im
3+
LOCALE=en
54
ORAMA_PRIVATE_API_KEY_EN=
65
ORAMA_PRIVATE_API_KEY_ZH_HANS=

apps/docs/global.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import type { routing } from '@/i18n/routing';
21
import type messages from './messages/en.json';
32

43
declare module 'next-intl' {
54
interface AppConfig {
6-
Locale: (typeof routing.locales)[number];
75
Messages: typeof messages;
86
}
97
}

apps/docs/source.config.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ if (!asyncMode && process.env.NODE_ENV === 'development') {
1717
);
1818
}
1919

20-
const defaultDocsOptions = {
20+
// You can customise Zod schemas for frontmatter and `meta.json` here
21+
// see https://fumadocs.dev//docs/mdx/collections#define-docs
22+
export const docs = defineDocs({
23+
dir: `content/${process.env.LOCALE}/docs`,
2124
docs: {
2225
async: asyncMode,
2326
schema: frontmatterSchema.extend({
@@ -35,18 +38,6 @@ const defaultDocsOptions = {
3538
meta: {
3639
schema: metaSchema,
3740
},
38-
};
39-
40-
// You can customise Zod schemas for frontmatter and `meta.json` here
41-
// see https://fumadocs.dev//docs/mdx/collections#define-docs
42-
export const docs_en = defineDocs({
43-
dir: 'content/en/docs',
44-
...defaultDocsOptions,
45-
});
46-
47-
export const docs_zh_hans = defineDocs({
48-
dir: 'content/zh-hans/docs',
49-
...defaultDocsOptions,
5041
});
5142

5243
export default defineConfig({
File renamed without changes.

apps/docs/src/app/[locale]/(home)/page.tsx renamed to apps/docs/src/app/(home)/page.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Locale, useTranslations } from 'next-intl';
1+
import { useTranslations } from 'next-intl';
22
import { getTranslations } from 'next-intl/server';
33
import Link from 'next/link';
44

@@ -27,11 +27,8 @@ export default function HomePage() {
2727
// return routing.locales.map((locale) => ({ locale }));
2828
// }
2929

30-
export async function generateMetadata(props: {
31-
params: Promise<{ locale: Locale }>;
32-
}) {
33-
const { locale } = await props.params;
34-
const t = await getTranslations({ locale, namespace: 'HomePage' });
30+
export async function generateMetadata() {
31+
const t = await getTranslations('HomePage');
3532

3633
return {
3734
title: t('title'),

apps/docs/src/app/[locale]/static/[page]/route.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

apps/docs/src/app/[locale]/docs/[[...slug]]/page.tsx renamed to apps/docs/src/app/docs/[[...slug]]/page.tsx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { DocsLayout } from '@/components/layout';
2-
import { routing } from '@/i18n/routing';
32
import { type RouterType, routerTypeCookie } from '@/lib/const';
43
import { getPage } from '@/lib/page';
54
import { getDocsLayoutTree, getPageTreePeers } from '@/lib/pageTree';
6-
import { type Page, type Source, sourceMap } from '@/lib/source';
5+
import { type Page, type Source, source } from '@/lib/source';
76
import { getDocId, getDocUrl, parseDocId } from '@/lib/utils';
87
import { getMDXComponents } from '@/mdx-components';
98
import { Identity } from '@/mdx/Identity';
@@ -12,21 +11,21 @@ import { Card, Cards } from 'fumadocs-ui/components/card';
1211
import { createRelativeLink } from 'fumadocs-ui/mdx';
1312
import { DocsBody, DocsPage, DocsTitle } from 'fumadocs-ui/page';
1413
import { type Locale, useLocale } from 'next-intl';
14+
import { getLocale } from 'next-intl/server';
1515
import { cookies } from 'next/headers';
1616
import { notFound } from 'next/navigation';
1717

1818
export default async function Docs(props: {
19-
params: Promise<{ locale: Locale; slug: string[] }>;
19+
params: Promise<{ slug: string[] }>;
2020
}) {
21+
const locale: Locale = await getLocale();
2122
const routerType = (await cookies()).get(routerTypeCookie)
2223
?.value as RouterType;
2324
const params = await props.params;
2425
const slug = params.slug || [];
25-
const locale = params.locale;
26-
const source = sourceMap[locale];
2726
const docUrl = getDocUrl(slug);
2827
const docId = getDocId(locale, docUrl);
29-
const page = getPage(locale, docUrl);
28+
const page = getPage(docUrl);
3029
if (!page) notFound();
3130
const { isApp, isPages } = parseDocId(docId);
3231
// @ts-ignore
@@ -39,7 +38,7 @@ export default async function Docs(props: {
3938
const ref = page.data.source;
4039
if (ref) {
4140
const refUrl = getDocUrl(ref);
42-
const refPage = getPage(locale, refUrl);
41+
const refPage = getPage(refUrl);
4342
if (!refPage) notFound();
4443
// @ts-ignore
4544
const { body: MdxContent2, toc: toc2 } = refPage.data.load
@@ -104,7 +103,7 @@ function DocsRelated({ page }: { page: Page }) {
104103
const relatedLinks = page.data.related?.links || [];
105104
const pages = relatedLinks
106105
.map((link) => {
107-
return getPage(locale, getDocUrl(link));
106+
return getPage(getDocUrl(link));
108107
})
109108
.filter(Boolean) as Page[];
110109
return (
@@ -124,24 +123,17 @@ function DocsRelated({ page }: { page: Page }) {
124123
);
125124
}
126125

127-
// export async function generateStaticParams() {
128-
// const staticParams = routing.locales.flatMap((locale) => {
129-
// return sourceMap[locale].generateParams().map((params) => {
130-
// return {
131-
// locale,
132-
// ...params,
133-
// };
134-
// });
135-
// });
136-
// return staticParams;
137-
// }
126+
export async function generateStaticParams() {
127+
if (process.env.GEN_DOC_STATIC !== 'true') return [];
128+
return source.generateParams();
129+
}
138130

139131
export async function generateMetadata(props: {
140-
params: Promise<{ slug?: string[]; locale: Locale }>;
132+
params: Promise<{ slug?: string[] }>;
141133
}) {
142134
const params = await props.params;
143135
const url = getDocUrl(params.slug);
144-
const page = getPage(params.locale, url);
136+
const page = getPage(url);
145137
if (!page) notFound();
146138

147139
return {
File renamed without changes.

apps/docs/src/app/[locale]/layout.tsx renamed to apps/docs/src/app/layout.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
import { NextIntlClientProvider, hasLocale } from 'next-intl';
22
import './global.css';
3-
import { Provider } from '@/app/[locale]/provider';
4-
import { routing } from '@/i18n/routing';
3+
import { Provider } from '@/app/provider';
54

6-
import { setRequestLocale } from 'next-intl/server';
5+
import { getLocale } from 'next-intl/server';
76
import { Inter } from 'next/font/google';
8-
import { notFound } from 'next/navigation';
97

108
const inter = Inter({
119
subsets: ['latin'],
1210
});
1311

1412
export default async function Layout({
1513
children,
16-
params,
1714
}: {
1815
children: React.ReactNode;
19-
params: Promise<{ locale: string }>;
2016
}) {
21-
// Ensure that the incoming `locale` is valid
22-
const { locale } = await params;
23-
if (!hasLocale(routing.locales, locale)) {
24-
notFound();
25-
}
26-
// Enable static rendering
27-
setRequestLocale(locale);
17+
const locale = await getLocale();
2818

2919
return (
3020
<html lang={locale} className={inter.className} suppressHydrationWarning>
File renamed without changes.

0 commit comments

Comments
 (0)