// utils/getRouteLang.ts import { locales, defaultLocale } from "@/i18n/config"; export function getRouteLang(): string { if (typeof window === "undefined") return defaultLocale; // 1)Fall back to the first non-empty pathname segment const rawSegments = window.location.pathname.split("/"); // e.g. ['', 'uz', 'path', ...] const segments = rawSegments.filter(Boolean); // removes empty strings if (segments.length > 0) { const candidate = segments[0]; // first segment after root if (locales.includes(candidate as (typeof locales)[number])) return candidate; } // 2) final fallback return defaultLocale; }