microapps / gatsby-plugin-react-i18next

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

changeLanguage does not clear first locale from url #122

Open francinedcd opened 2 years ago

francinedcd commented 2 years ago

When the window.location.href has no path parameters other than the currently selected locale code, calling changeLanguage("--new locale--") adds the new language to the end of the path without removing the original locale. The result is a url with 2 locales, which 404s on my system.

Steps to reproduce:

  1. Go to site home page => url is http://localhost:8000/
  2. Select first locale by calling changeLanguage('en') => url is http://localhost:8000/en
  3. Select new locale by calling changeLanguage('zh-cn') => url is http://localhost:8000/zh-cn/en

It looks like the changeLanguage(...) function assumes that there will be atleast 1 path parameter after the locale

gallardoandres18 commented 2 years ago

i am having the same problem, were you able to solve it? thanks