Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not being able to setup gatsby-plugin-react-i18next #176

Open
m-medeiros1 opened this issue Jun 14, 2023 · 4 comments
Open

Not being able to setup gatsby-plugin-react-i18next #176

m-medeiros1 opened this issue Jun 14, 2023 · 4 comments

Comments

@m-medeiros1
Copy link

m-medeiros1 commented Jun 14, 2023

Hi everyone!

I'm trying to setup the plugin on a website but it doesn't seem to work. I already followed multiple setup guides but no success so far.

My gatsby-config:

{
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/locales`,
        name: `locale`
      }
    },
    {
      resolve: 'gatsby-plugin-react-i18next',
      options: {
        languages: ["en", "es", "pt"],
        defaultLanguage: "en",
        siteUrl: "https://siteurl.com/",
        i18nextOptions: {
          // debug: true,
          fallbackLng: defaultLanguage,
          supportedLngs: languages,
          defaultNS: 'common',
          interpolation: {
            escapeValue: false, // not needed for react as it escapes by default
          }
        },
      },
    },

My folder structure:

| locales
| - en
| - - common.js
| - es
| - - common.js
| - pt
| - - common.js
| src
| - home.js
| gatsby-config
| languages.js

How I'm trying to pull the data in a page:

import { useTranslation, Trans } from "gatsby-plugin-react-i18next"
import { graphql } from "gatsby"

const Home = () => {
  const { t } = useTranslation('translations')
  ...
  //Tried both ways, neither works
  <Trans i18nKey="Open a new chapter in technology" > Open a new chapter in technology </Trans>
  <h1> {t('Open a new chapter in technology')} </h1>
  ...
}

export const query = graphql`
  query ($language: String!) {
    locales: allLocale(
      filter: { ns: { in: ["common"] }, language: { eq: $language } }
    ) {
      edges {
        node {
          ns
          data
          language
        }
      }
    }
  }
`;

The only information/insight about why it is not working is this message in DevTools:

No translations were found in "locales" key for "/". 
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
        }
      }
    }
  }
`;

I obviously tried also with this query in the page, but the same error message appears and nothing changes.

The language switcher seems to be working (url changes on click) but nothing beyond that.

Any help would be highly appreciated as we have been stuck with this issues for a while already and no hint as to where to go next.

@hanaakhojhove
Copy link

having the same issue here !!!

@jishnupsamal
Copy link

Same here.
Any solution @m-medeiros1 @hanaakhojhove?

@trihargianto
Copy link

Same here 😅

@alanhchoi
Copy link

alanhchoi commented Jan 19, 2024

I resolved this error by adding this GraphQL query to a page as written in the readme page.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants