init
This commit is contained in:
32
i18n/request.ts
Normal file
32
i18n/request.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
|
||||
if (locale?.startsWith('zh')) {
|
||||
locale = 'zh';
|
||||
} else if (locale?.startsWith('en')) {
|
||||
locale = 'en';
|
||||
}
|
||||
// else if (locale?.startsWith('vi')) {
|
||||
// locale = 'vi';
|
||||
// }
|
||||
else {
|
||||
locale = 'zh';
|
||||
}
|
||||
|
||||
// Ensure that a valid locale is used
|
||||
if (!locale || !routing.locales.includes(locale as any)) {
|
||||
return {
|
||||
locale: routing.defaultLocale,
|
||||
messages: (await import(`./messages/${routing.defaultLocale}.json`)).default
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
locale,
|
||||
messages: (await import(`./messages/${locale}.json`)).default
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user