I'm trying to create a multilingual blog with Strapi v4 and Nextjs 18n using static routes with data from an api, with getStaticProps and getStaticPaths. When I make the request everything works correctly in the default language, the problem is when I change the language I can't display the information and I don't understand the reason, I have reviewed the documentation and I haven't been able to find the problem. If someone can guide me. Thanks in advance!
export async function getStaticPaths({ locales }) {
const url = `${process.env.API_URL}/api/posts?populate=*`
const response = await fetch(url);
const posts= await response.json();
const {data} = posts;
const paths = locales.map((locale) => posts.map((post) => ({
params: {posts: posts.id.toString(), locale: locale.toString()}
}))).flat()
return {
paths,
fallback: true,
}
}
export async function getStaticProps({params:{id, locale}}) {
const sortItems = `sort=rank`;
const url = `${process.env.API_URL}/api/posts?filters[id][url][$eq]=${id}&${locale}&${sortItems}`;
const response = await fetch(url);
const posts = await response.json();
return {
props: {
posts
}
}
}