language Switcher added
This commit is contained in:
16
i18n/config.ts
Normal file
16
i18n/config.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export const locales = ["uz", "ru", "en"] as const
|
||||
export type Locale = (typeof locales)[number]
|
||||
|
||||
export const defaultLocale: Locale = "uz"
|
||||
|
||||
export const localeNames: Record<Locale, string> = {
|
||||
uz: "O'zbekcha",
|
||||
ru: "Русский",
|
||||
en: "English",
|
||||
}
|
||||
|
||||
export const localeFlags: Record<Locale, string> = {
|
||||
uz: "🇺🇿",
|
||||
ru: "🇷🇺",
|
||||
en: "🇬🇧",
|
||||
}
|
||||
25
i18n/request.ts
Normal file
25
i18n/request.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// i18n/request.ts
|
||||
import { getRequestConfig } from 'next-intl/server';
|
||||
import { headers } from 'next/headers';
|
||||
|
||||
const LOCALES = ["uz", "ru", "en"] as const;
|
||||
const DEFAULT_LOCALE = "uz";
|
||||
|
||||
type Locale = typeof LOCALES[number];
|
||||
|
||||
export default getRequestConfig(async () => {
|
||||
const headersList = await headers();
|
||||
|
||||
// ✅ Middleware allaqachon locale'ni set qilgan
|
||||
const locale = headersList.get('x-locale') || DEFAULT_LOCALE;
|
||||
|
||||
// Validate
|
||||
const validLocale = LOCALES.includes(locale as Locale)
|
||||
? locale
|
||||
: DEFAULT_LOCALE;
|
||||
|
||||
return {
|
||||
locale: validLocale,
|
||||
messages: (await import(`../messages/${validLocale}.json`)).default,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user