microapps / gatsby-plugin-react-i18next

Easily translate your Gatsby website into multiple languages
MIT License
121 stars 72 forks source link

No translations were found error #116

Open developer-bart opened 2 years ago

developer-bart commented 2 years ago

I'm using the plugin to handle language state en automate language urls only. I don't want to use local translation files but instead use Prismic CMS via graphql directly.

These are my plugin options in gatsby-config.js:

{
      resolve: 'gatsby-plugin-react-i18next',
      options: {
        languages: ['nl', 'en'],
        defaultLanguage: 'nl',
        siteUrl: 'https://my-url.com',
      },
    },

I'm using the provided language inside the pageContext to query Prismic data with the correct language like so:

export const homepageQuery = graphql`
  query homepage($language: String!) {
    prismicHomepage(lang: { eq: $language }) {
      data {
        intro_title {
          text
        }
      }
    }
  }
`

Using this setup I have this console error in my development environment I'd like to get rid off:

🚫  No translations were found in "locales" key for "/404/". 
You need to add a graphql query to every page like this:

export const query = graphql`
  query($language: String!) {
    locales: allLocale(language: {eq: $language}}) {
      edges {
        node {
          ns
          data
          language
        }
      }
    }
  }
`;

Help would be much appreciated!

jirsbek commented 2 years ago

Had the same problem. I've solved this by creating an empty default-lang-folder/translation.json for my default language.

febeling commented 2 years ago

You need to configure the gatsby-filesystem-plugin, which creates the graphql contents that i18n builds on. Or that it was in my case.

I think it could also result from querying for nodes directly, as the plugin expects edges.node.