language Switcher added

This commit is contained in:
nabijonovdavronbek619@gmail.com
2026-01-27 17:36:09 +05:00
parent e87a26d74c
commit de2554a2e7
21 changed files with 830 additions and 32 deletions

16
i18n/config.ts Normal file
View 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
View 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,
};
});