Files
ignum/request/getLang.ts
nabijonovdavronbek619@gmail.com 3c862ea104 connetcted to backend: form request
2026-02-05 11:02:57 +05:00

19 lines
639 B
TypeScript

// 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;
}