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.

Default language not working as expected

See original GitHub issue

Summary of the issue

Default language not working as expected. Default language is set to Spanish (es), but the root page gets redirected to English (en)

Expected behavior

✅ When visiting the index page http://mysite.com/ it should load the page normally using the default language Spanish (es)

Current behavior

❗ When visiting the index page http://mysite.com/ it gets automatically redirected to http://mysite.com/en/

Setup details

The allowed languages for the site are:

  • English (en)
  • French (fr)
  • Spanish (es)

Version used:

    "gatsby": "^3.10.1"
    "i18next": "^20.4.0"
    "react-i18next": "^11.11.4"
    "gatsby-plugin-react-i18next": "^1.1.1"

Gatsby configuration:

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
whitedwarf2000commented, Dec 8, 2021

Hi @AnderUstarroz , I have added generateDefaultLanguagePage: true and redirect: false to options and it work for me

2reactions
nextlevelshitcommented, Nov 10, 2021

Guys, sorry to say, but read the docs

Setting a defaultLanguage means that you will render this language, when the user navigates to root /. Instead of navigating him/her to /${defaultLanguage} it will show the index page with your choice.

It is super tricky to be honest. I am also struggling with many side effects, but the developers have done stuff intentionally. And pushing such PR like @chenxizhang did is a huge provocation. At least you could have stuck to the code style convention. Instead of reading the documentation you’re pushing such heavily unreflected changes to all of us? C’mon, you can do a better job!

If you want to gain full control of your client routes, you will probably need to implement a gatsby-node.js file or add a router into your pages/index.js for instance. If you want to know more, I am available for help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Change language not working when device default ...
I have problem to change language when my device language not be English (For example Portuguese). This is my code:
Read more >
Default language not working properly - Drupal Answers
Everything works as expected but there is one problem: when the site is loaded it takes the English as default language. Then if...
Read more >
Survey123 Default Language Not Working - Esri Community
I'm creating a Survey123 form that is intended to default to French, which needs to include all the buttons and "Page 1 of...
Read more >
Tips for Troubleshooting the Default Language of a Job ...
First, check the Job Requisition XML defaultlocale definition. If the expected default locale does not appear, then check the default language in Admin ......
Read more >
Default language not working - Google Groups
Since Enketo introduced a feature to sync UI and form language, the default form language defined in the form may not do what...
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