prmbr-image-mksaas/src/i18n/routing.ts
javayhu df1c75f56a chore: upgrade next-intl to version 4.0.0 and update type definitions
- Update `next-intl` dependency from version 3.26.5 to 4.0.0
- Modify global type definitions to include new `Locale` and `Messages` types
- Refactor various components and pages to use `Locale` type for params
- Enhance internationalization handling by integrating `hasLocale` checks
- Clean up imports and ensure consistent usage of `next-intl` features
2025-03-13 00:23:37 +08:00

51 lines
1.7 KiB
TypeScript

import { defineRouting } from 'next-intl/routing';
export const LOCALE_LIST: Record<string, { flag: string; name: string }> = {
en: { flag: '🇺🇸', name: 'English' },
zh: { flag: '🇨🇳', name: '中文' },
};
export const DEFAULT_LOCALE = 'en';
export const LOCALES = Object.keys(LOCALE_LIST);
// The name of the cookie that is used to determine the locale
export const LOCALE_COOKIE_NAME = 'NEXT_LOCALE';
/**
* Next.js internationalized routing
*
* https://next-intl.dev/docs/routing
* https://github.com/amannn/next-intl/blob/main/examples/example-app-router/src/i18n/routing.ts
*/
export const routing = defineRouting({
// A list of all locales that are supported
locales: LOCALES,
// Default locale when no locale matches
defaultLocale: DEFAULT_LOCALE,
// Auto detect locale
// https://next-intl.dev/docs/routing/middleware#locale-detection
localeDetection: false,
// Once a locale is detected, it will be remembered for
// future requests by being stored in the NEXT_LOCALE cookie.
localeCookie: {
name: LOCALE_COOKIE_NAME,
},
// The prefix to use for the locale in the URL
// https://next-intl.dev/docs/routing#locale-prefix
localePrefix: 'as-needed',
// The pathnames for each locale
// https://next-intl.dev/docs/routing#pathnames
//
// https://next-intl.dev/docs/routing/navigation#link
// if we set pathnames, we need to use pathname in LocaleLink
// pathnames: {
// // used in sietmap.ts
// "/": "/",
// // used in blog pages
// "/blog/[...slug]": "/blog/[...slug]",
// "/blog/category/[slug]": "/blog/category/[slug]",
// },
});
// export type Pathnames = keyof typeof routing.pathnames;
// export type Locale = (typeof routing.locales)[number];