Define the i18n configurations in a file, we will import it with @/i18n in this guide.
i18n.ts
import type { I18nConfig } from 'fumadocs-core/i18n';export const i18n: I18nConfig = { defaultLanguage: 'en', languages: ['en', 'cn'],};
Change your current source configurations.
source.ts
import { i18n } from '@/i18n';import { loader } from 'fumadocs-core/source';export const source = loader({ i18n, // other options});
Update the usages to your source:
import { source } from '@/app/source';// get page treesource.pageTree[params.lang];// get pagesource.getPage(params.slug, params.lang);// get pagessource.getPages(params.lang);
To hide the locale prefix, for example, use / instead of /en, use the hideLocale option.
Mode
Description
always
Always hide the prefix, detect locale from cookies
default-locale
Only hide the default locale
never
Never hide the prefix (default)
It uses NextResponse.rewrite under the hood.
import type { I18nConfig } from 'fumadocs-core/i18n';export const i18n: I18nConfig = { defaultLanguage: 'en', languages: ['en', 'cn'], hideLocale: 'default-locale',};
It's not recommended to use always.
On this mode, locale is stored as a cookie, read and set on the middleware.
This may cause undesired cache problems on your hosting platform, and need to pay extra attention on SEO to ensure search engines can index your pages correctly.