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

Can't switch to specific locale *by path* if route path was customized #641

Closed
mattickx opened this issue Mar 24, 2020 · 14 comments
Closed

Comments

@mattickx
Copy link

mattickx commented Mar 24, 2020

Version

v6.7.0

Reproduction link

#554

Steps to reproduce

Please add following tests:

expect(window.$nuxt.localePath('/about-us', 'fr')).toBe('/fr/a-propos')
expect(window.$nuxt.localePath({ path: '/about-us' }, 'fr')).toBe('/fr/a-propos')

Which will fail as both will result in /fr/about-us instead of /fr/a-propos
Tested with master branch.

What is expected ?

localePath('/about-us', 'fr') to be /fr/a-propos

What is actually happening?

localePath('/about-us', 'fr') becomes /fr/about-us

Additional comments?

Using the older way with route names still works correctly, but this usage would make my life easier.

This bug report is available on Nuxt community (#c426)
@rchl
Copy link
Collaborator

rchl commented Mar 25, 2020

It's not really about #554 as that one just matched what was already possible before (your second test). The thing is that is not really supposed to work. In theory, we could try to come up with some solution but that would be an extra feature that would require storing a map of paths assigned to a specific route.

@rchl rchl changed the title Pull request #554 wrongly implemented. Can't switch to specific locale *by path* if route path was customized Apr 7, 2020
@rchl
Copy link
Collaborator

rchl commented May 14, 2020

Those finding this issue should know that it works when passing route's "name" to localePath rather than a path.

Every page route has a name attached to it. They follow certain pattern but if unsure, one can always look inside generated .nuxt/router.js file, at the list of routes.

@FreekVR
Copy link

FreekVR commented Jun 18, 2020

I'm having the same issue, even without supplying the second parameter with the alternative language it's not working sometimes for customized paths.

(An alternative to using the .nuxt/routes.js source-file is to use the "Router" tab in your browser's Vue Devtools)

@stale
Copy link

stale bot commented Sep 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 26, 2020
@rchl rchl removed the stale label Sep 27, 2020
@stale
Copy link

stale bot commented Nov 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@katerlouis
Copy link

katerlouis commented Feb 9, 2021

It's also not working for me.
Shouldn't the docs be updated then?

image

Or is there a way to fix this / support this functionality?

@rchl
Copy link
Collaborator

rchl commented Feb 9, 2021

It's also not working for me.
Shouldn't the docs be updated then?

The docs could always be improved to make things clearer.
That said, that example is not necessarily wrong as that works for cases when route names are not customized.

Or is there a way to fix this / support this functionality?

There is. That's why this feature request is open. :)

@katerlouis
Copy link

Is the following what you mean by "customized"?

nuxtI18n: {
  paths: {
    de: '/karriere',
  },
},

@rchl
Copy link
Collaborator

rchl commented Feb 9, 2021

Yes. This or through the pages module configuration option.

@katerlouis
Copy link

Okay, I just checked it, and yeah you're right. So basically localePath('/career') only prepends the locale and doesn't take customized paths into consideration.

Please correct me if I'm wrong, but it feels like supporting customized paths for this path-parameters shouldn't be too difficult, right?

@rchl
Copy link
Collaborator

rchl commented Feb 9, 2021

It's fairly complex to implement that in a robust way.

To add to that, there is currently no support for custom paths when using NO_PREFIX strategy but there should be. That needs to be taken into consideration when implementing this feature.

There is some veeeery early attempt at that in https://github.com/nuxt-community/i18n-module/tree/fix/no-prefix-rename

@Energon7
Copy link

Energon7 commented Mar 4, 2021

@rchl fix here: #1088

@rchl
Copy link
Collaborator

rchl commented Mar 4, 2021

Please hold off announcing a fix before it's properly tested and reviewed.

@rchl
Copy link
Collaborator

rchl commented Mar 8, 2021

Should be fixed by #1088

@rchl rchl closed this as completed Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants