mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-10 17:26:38 +08:00
feat(frontend): add next-intl bilingual i18n for core paths
Wire next-intl without locale routes, add zh-CN/en catalogs, language switcher, and migrate layout/auth/settings UI copy. Document i18n rules in AGENTS.md and keep static export builds working.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { cookies, headers } from 'next/headers';
|
||||
import { getRequestConfig } from 'next-intl/server';
|
||||
import {
|
||||
defaultLocale,
|
||||
isAppLocale,
|
||||
localeCookieName,
|
||||
normalizeLocale,
|
||||
pickLocaleFromAcceptLanguage,
|
||||
type AppLocale,
|
||||
} from './config';
|
||||
|
||||
async function resolveRequestLocale(): Promise<AppLocale> {
|
||||
try {
|
||||
const cookieStore = await cookies();
|
||||
const cookieLocale = cookieStore.get(localeCookieName)?.value;
|
||||
if (isAppLocale(cookieLocale)) {
|
||||
return cookieLocale;
|
||||
}
|
||||
if (cookieLocale) {
|
||||
return normalizeLocale(cookieLocale);
|
||||
}
|
||||
} catch {
|
||||
// Static export / non-request contexts cannot read cookies.
|
||||
}
|
||||
|
||||
try {
|
||||
const headerStore = await headers();
|
||||
const acceptLanguage = headerStore.get('accept-language');
|
||||
return pickLocaleFromAcceptLanguage(acceptLanguage);
|
||||
} catch {
|
||||
// Static export build time.
|
||||
}
|
||||
|
||||
return defaultLocale;
|
||||
}
|
||||
|
||||
export default getRequestConfig(async () => {
|
||||
const locale = await resolveRequestLocale();
|
||||
const messages = (await import(`../messages/${locale}.json`)).default;
|
||||
return {
|
||||
locale,
|
||||
messages,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user