feat: setup globals (Footer), sqlite migration, seed update and access rules
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { i18n } from "../i18n.config";
|
||||
|
||||
type LocalizedSlugs = Record<string, string>;
|
||||
|
||||
export function clientGetLocalizedSlugs(slugField: any): LocalizedSlugs {
|
||||
const result: LocalizedSlugs = {};
|
||||
if (!slugField || typeof slugField !== 'object') {
|
||||
return result;
|
||||
}
|
||||
for (const [locale, value] of Object.entries(slugField)){
|
||||
if (!i18n.locales.some(l => l.code === locale)) {
|
||||
continue;
|
||||
}
|
||||
if (typeof value !== 'string') {
|
||||
continue;
|
||||
}
|
||||
const slug = value.trim();
|
||||
if (!slug) {
|
||||
continue;
|
||||
}
|
||||
result[locale] = slug;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Klient-safe wersja funkcji switchLocalePath z ipal-kit, omijająca problem
|
||||
* importowania modułów Node (np. fs, net) z głównego pliku index.js ipal-kit
|
||||
* w komponentach "use client".
|
||||
*/
|
||||
export function clientSwitchLocalePath(
|
||||
pathname: string,
|
||||
targetLocale: string,
|
||||
slugs?: LocalizedSlugs,
|
||||
prefix?: LocalizedSlugs,
|
||||
homeSlug: string = "home"
|
||||
): string {
|
||||
// Jeśli mamy zlokalizowane slugi ze strony (przekazane z page.tsx -> Context -> LanguageSwitcher)
|
||||
if (slugs && slugs[targetLocale]) {
|
||||
const targetSlug = slugs[targetLocale];
|
||||
|
||||
// Jeśli mamy prefix (dla kolekcji, np. /pl/uslugi/...)
|
||||
if (prefix && prefix[targetLocale]) {
|
||||
return `/${targetLocale}/${prefix[targetLocale]}/${targetSlug}`;
|
||||
}
|
||||
|
||||
if (targetSlug === homeSlug) {
|
||||
return `/${targetLocale}`;
|
||||
}
|
||||
return `/${targetLocale}/${targetSlug}`;
|
||||
}
|
||||
|
||||
// Fallback (zwykły prefix swap), użyteczny dla stron nienależących do CMS lub
|
||||
// gdy slugs nie zostały (jeszcze) przekazane do kontekstu
|
||||
const segments = pathname.split('/').filter(Boolean);
|
||||
if (segments.length > 0 && i18n.locales.some((l: any) => l.code === segments[0])) {
|
||||
segments[0] = targetLocale;
|
||||
} else {
|
||||
segments.unshift(targetLocale);
|
||||
}
|
||||
return `/${segments.join('/')}`;
|
||||
}
|
||||
Reference in New Issue
Block a user