You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
786 B
32 lines
786 B
import { fetchAPI } from "./api" |
|
|
|
export async function getLocalizedPage(targetLocale, pageContext) { |
|
const localization = pageContext.localizations.data.find( |
|
(localization) => localization.attributes.locale === targetLocale |
|
) |
|
const localePage = await fetchAPI(`/pages/${localization.id}`) |
|
return localePage |
|
} |
|
|
|
export function localizePath(page) { |
|
const { locale, defaultLocale, slug } = page |
|
|
|
if (locale === defaultLocale) { |
|
// The default locale is not prefixed |
|
return `/${slug}` |
|
} |
|
|
|
// The slug should have a localePrefix |
|
return `/${locale}/${slug}` |
|
} |
|
|
|
export function getLocalizedPaths(page) { |
|
const paths = page.locales.map((locale) => { |
|
return { |
|
locale: locale, |
|
href: localizePath({ ...page, locale }), |
|
} |
|
}) |
|
|
|
return paths |
|
}
|
|
|