NextJS complex routing & language support

I had a similar issue here.

I ended up doing a costly fetch on getStaticProps and created a new object to give to my layouts and language switchers

  // fetch alternate categories slugs
  var alternativeLang = [];
  await Promise.all(
    doc.alternate_languages.map(async (lang) => {
      const fetchLang = await client.getByID(lang.id);

      alternativeLang = [
        ...alternativeLang,
        {
          id: lang.id,
          uid: lang.uid,
          type: lang.type,
          url: `/${lang.lang}/blog/${fetchLang.data.category.uid}/${lang.uid}`,
          category: fetchLang.data.category.uid,
          lang: lang.lang,
        },
      ];
    })
  );

Edit: it is costly but since it's on GetStaticProps it's handled asynchronously from the user so it's not that big of a deal