Nextjs / Strapi: how fetch data with locale context

Hello :smiley:

I’m new to Strapi and I’m trying to write an API request allowing me to obtain, depending on the specialty chosen, all the associated results (relation between my specialties table and results) which I manage to do without problem like this:

export const getStaticProps: GetStaticProps = async (context) => {
  const slug = context.params?.slug;

  const results = await fetcher(
    `${process.env.NEXT_PUBLIC_API_BASE_URL}/api/specialites?filters[Slug][$eq]=${slug}&populate[0]=resultats&populate[1]=Illustration&populate[2]=resultats.Image`
  );

  return {
    props: {
      results: results.data,
    },

    revalidate: 2 * 60,
  };
};

however where I block is to recover the specialties and therefore the results in English! Basically I would like that depending on the context.locale I can retrieve the right elements in the corresponding language, any idea how to do it ?

export const getStaticProps: GetStaticProps = async (context) => {
  const slug = context.params?.slug;
  const { locale } = context

  const language = locale === "en" ? "en-EU" : "fr-FR";

  const results = await fetcher(
    `${process.env.NEXT_PUBLIC_API_BASE_URL}/api/specialites?locale=${language}?filters[Slug][$eq]=${slug}&populate[0]=resultats&populate[1]=Illustration&populate[2]=resultats.Image`
  );

  return {
    props: {
      results: results.data,
    },

    revalidate: 2 * 60,
  };
};

I try this and so many things but the result is the same, i don’t understand how it’s works … if someone have an advice/solution don’t hesitate :blush:

Have a good day

url query only has one “?”.

specialites?locale=${language}?filters
specialites?locale=${language}&filters

try this:

  const results = await fetcher(
    `${process.env.NEXT_PUBLIC_API_BASE_URL}/api/specialites?locale=${language}&filters[Slug][$eq]=${slug}&populate[0]=resultats&populate[1]=Illustration&populate[2]=resultats.Image`
  );

Ty for your help :slight_smile:

like this it’s work yes “/api/resultats?locale=en-EU” but not if I put the he rest of the URL after:
‘&filters[Slug][$eq]=${slug}&populate[0]=resultats&populate[1]=Illustration&populate[2]=resultats.Image`’

idk why or how do this … I really need to fetch elements with the good locale and filter them in the same time i don’t want to fetch them all and apply filter after it’s really annoying :frowning: