Snapshot of uncommitted work: landing, bots, prod infra, partner cabinet, backoffice stage 1
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
45d7512d2b
commit
d452824c62
314 files changed
+44394
-121
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import { isLocale } from '@barev/i18n';
|
||||
import { cookies, headers } from 'next/headers';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
type SearchParams = Promise<Record<string, string | string[] | undefined>>;
|
||||
|
||||
/** Адрес без языка → язык из cookie (выбор на лендинге) или Accept-Language; ?a= и UTM сохраняются */
|
||||
export async function redirectToLocale(searchParams: SearchParams, path = ''): Promise<never> {
|
||||
const [sp, c, h] = await Promise.all([searchParams, cookies(), headers()]);
|
||||
const saved = c.get('barev_lang')?.value;
|
||||
const accepted = (h.get('accept-language') ?? '')
|
||||
.split(',')
|
||||
.map((p) => p.split(';')[0]!.trim().split('-')[0]!.toLowerCase())
|
||||
.find(isLocale);
|
||||
const locale = isLocale(saved) ? saved : (accepted ?? 'ru');
|
||||
const qs = new URLSearchParams();
|
||||
for (const [k, v] of Object.entries(sp)) if (typeof v === 'string') qs.set(k, v);
|
||||
redirect(`/${locale}${path}${qs.size ? `?${qs}` : ''}`);
|
||||
}
|
||||
Reference in new issue
Block a user