connetcted to backend: form request
This commit is contained in:
18
request/getLang.ts
Normal file
18
request/getLang.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user