question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

languages from useI18next() contains only 1 language

See original GitHub issue

I’m running gatsby 4.12.1 with react 18.2.0 using latest version of gatsby-plugin-react-i18next. I followed the examples included in the plugin. When I try to obtain the list of available languages using the following code:

const {languages, originalPath} = useI18next();

I keep getting only ['en'] in the languages array even if there’s no en language defined in my setup.

Here’s how my gatsby-config.js looks like:

...
  plugins: [
{
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/locales`,
        name: `locale`
      }
    },
    {
      resolve: `gatsby-plugin-react-i18next`,
      options: {
        localeJsonSourceName: `locale`,
        languages: [`de`, `es`],
        defaultLanguage: `de`,
        siteUrl: `http://localhost:8000/`,
        i18nextOptions: {
          interpolation: {
            escapeValue: false 
          },
          keySeparator: false,
          nsSeparator: false
        },
      }
    }
]
...

I’ve created the following files:

  • locales/de/translation.json
  • locales/es/translation.json

All seems to be working fine, If I access http://localhost:8000/ I get the German translations, If I access http://localhost:8000/es I get the Spanish. However, when I try to list the available languages by using the following code:

const {languages, originalPath} = useI18next();

no matter what, languages always contains a single element en.

Does anyone have any idea about what I’m doing wrong?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Dennnnnycommented, Nov 5, 2022
1reaction
Dennnnnycommented, Sep 26, 2022

I think it’s because of my gatsby-browser.tsx. so I can not access the whole languages. but, still I don’t know how to fix this yet, keep working on it 😭

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · microapps/gatsby-plugin-react-i18next - GitHub
Easily translate your Gatsby website into multiple languages - Issues ... languages from useI18next() contains only 1 language.
Read more >
A Guide to React Localization with i18next | Phrase
We can localize to any language and any number of languages. ... We can now use i18next's t() function to localize our app's...
Read more >
API - i18next documentation
Returns a t function that defaults to given language or namespace. All arguments can be optional/null. lng and ns params could be arrays...
Read more >
i18next/i18n Change Language not working with the whole ...
As you can see I use i18next.t('my-key') to get the translations and I export every component/page with "withTranslation()". So I don't know why ......
Read more >
Step-by-Step Guide to Use i18next in Gatsby App - Medium
In this example, I have two languages on my website. ... a simple app so we can put all the translation for one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found