next-drupal icon indicating copy to clipboard operation
next-drupal copied to clipboard

generating pages only for one locale

Open violabg opened this issue 2 years ago • 1 comments

in the context of [...slug]page, is it possible to statically generate (getStaticPaths) only the content on the default locale, and have other locales generated on demand?

another question, we have a site that is localised only for the Next.js label, I'm using next-translate, but not on content level, on the Drupal side (don't ask why :)). In Drupal however, every content fallback to the default locale without having an actual translation, so for each content you ask through locale/path you get the default localisation of the content. When I build the next site, I'm getting an error (in getStaticPaths) for the missing locales, is there any solution for this? or the only option is to actually translate each content?

violabg avatar Oct 05 '22 14:10 violabg

Hello, you can generate statically content for one locale. In [...slug] page, on getStaticPaths, just add the locale content you want to build, on the locale array.

export async function getStaticPaths(
  context: GetStaticPathsContext,
): Promise<GetStaticPathsResult> {
  // List all the paths to build
  const paths = await drupal.getStaticPathsFromContext(
    Array.from(RESOURCE_TYPES),
    { ...context, defaultLocale: "fr", locales: ["fr"] },
  );

  logger.debug({ paths }, "Retrieved paths");

  return {
    paths,
    fallback: "blocking",
  };
}

AlexandreBourdeaudhui avatar Jan 25 '24 12:01 AlexandreBourdeaudhui