wiziple / gatsby-plugin-intl

Gatsby plugin that turns your website into an internationalization-framework out of the box.
http://gatsby-starter-default-intl.netlify.com
325 stars 178 forks source link

Allow disabling automatic translations for certain pages #152

Open lucascaro opened 3 years ago

lucascaro commented 3 years ago

Hi, is it possible to disable automatic translations done by onCreatePage?

Currently, the plugin is doing a deletePage + createPage for each locale in onCreatePage, if we have pre-translated content (say a page from a headless cms) that needs to only exist on a given locale, right now we need to fake an intl object in page.context which would stop the plugin from duplicating the page.

createPage({
        path: `/${locale}${node.url}`,
        component: resolve('path/to/component.jsx'),
        context: {
          id: node.id,
          language: language,
          intl: {
            language: locale,
            languages: [],
            routed: true,
            originalPath: node.url.url,
            redirect: false,
            defaultLanguage,
          },
        },
      });

is there a cleaner way to do this?

if not, would a PR be accepted to add a flag that prevents the automatic translations? for example, by adding language to a page, the plugin could assume this page belongs to the passed-in language only and shouldn't attempt to translate?

createPage({
        path: `/${locale}${node.url}`,
        component: resolve('path/to/component.jsx'),
        context: {
          id: node.id,
          language: language,
        }
      });

any better ideas?

lucascaro commented 3 years ago

Example of how this could work: https://github.com/wiziple/gatsby-plugin-intl/pull/160