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

changeLanguage method doesn't adapt the URL with new language #938

Closed
ThaoD5 opened this issue Feb 9, 2021 · 4 comments
Closed

changeLanguage method doesn't adapt the URL with new language #938

ThaoD5 opened this issue Feb 9, 2021 · 4 comments

Comments

@ThaoD5
Copy link

ThaoD5 commented Feb 9, 2021

Hello,

I have been looking for hours now on a fix on why the changeLanguage method doesn't replace the previous language slug by the new one in the URL.

Using : i18n.changeLanguage('es');

I found this, the condition on initializedLanguageOnce but I have absolutely no idea AND didn't found anything related to this parameter that needs to be true.

The locale changing is happening correctly

Am I missing something ? Is this intended ? Is there something manually to add ?

Thanks a lot


( issue created based on someone having the same error in 2019 )

@vimutti77 That might be a separate issue. Any client side calls to changeLanguage should trigger this callback. If you think you're experiencing a bug there, please do open a separate issue.

Originally posted by @isaachinman in #413 (comment)

@isaachinman
Copy link
Contributor

Hi @ThaoD5, have you seen the simple example? If you add localeSubpaths, you'll be able to see the language changing the routing.

We have this behaviour covered by end-to-end tests.

If you believe you have found a bug, please provide a reproducible repository. Thanks!

@ThaoD5
Copy link
Author

ThaoD5 commented Feb 9, 2021

Hey @isaachinman
I have indeed worked with the localeSubpaths params you're talking about.
Here is a recap of my setup :
Next.config.js

// Locales route rewriting
const { nextI18NextRewrites } = require('next-i18next/rewrites')
const localeSubpaths = {
  es: 'es',
  en: 'en'
}

module.exports = withImages({
  // Locales Options
  rewrites: async () => nextI18NextRewrites(localeSubpaths),
  publicRuntimeConfig: {
    localeSubpaths,
  },
  i18n: {
    locales: ['en', 'es'],
    localeDetection: true,
    defaultLocale: 'en'
  },

Setup

const { localeSubpaths } = require('next/config').default().publicRuntimeConfig;

const i18n = new NextI18Next({
...
  defaultNS: 'translation',
  defaultLanguage: DEFAULT,
  localePath: '/locales',
  localeStructure: '{{lng}}/{{ns}}',
  localeExtension: 'json',
  otherLanguages: LANGUAGES,
  localeSubpaths,
...
});

That should be right, no ? Are there some known configs that breaks this ? We're building our new internal stack to include next I18next inside of it, but so far, the only issue remaining is this slug not getting replaced.

Thanks again for your help & time.

@ThaoD5
Copy link
Author

ThaoD5 commented Feb 9, 2021

On an additional note @isaachinman I saw that the example does have the same issue that I have ( and apparently it is supposed to be the "simple" example you just sent )
I currently have the same result than this specific example : Locales are adapted, but the slug is not adapted / added in the URL

https://next-i18next.com/

@isaachinman
Copy link
Contributor

I believe you are confusing the built-in NextJs internationalisation, and next-i18next. You do not need to put i18n in your next-config if you are using next-i18next@master. Please post on StackOverflow for help. Best of luck!

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

2 participants