languages from useI18next() contains only 1 language
See original GitHub issueI’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:
- Created a year ago
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gabric098 here’s what I found : https://andremonteiro.pt/gatsby-i18next-wrap-page-element/
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 😭