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

Possibility to localize dynamic routes #79

Closed
metalanti opened this issue May 1, 2018 · 13 comments
Closed

Possibility to localize dynamic routes #79

metalanti opened this issue May 1, 2018 · 13 comments

Comments

@metalanti
Copy link

What problem does this feature solve?

I'm not sure if it is possible :)
I have a route /article/:slug (en) and I'd like to translate it to other languages with translated slug
Eg: (en) /article/first-article and (de) /de/artikel/erste-artikel

Now I can do this:
article.vue

i18n: {
  paths: {
    de: '/artikel/:slug'
  }
},
data () {
  return {
    article: { // it comes from asyncData
      // title: { en: '...', de: '...' },
      // slug: { en: '...', de: '...' }
    }
  }
}

but I can't change the slug based on the article's data

What does the proposed changes look like?

I think the i18n.paths[locale] should accept a function with the access of this (data) and should return some Object:

de () {
  return {
    path: '/artikel/:slug',
    params: {
      slug: this.article.slug.de
    }
  }
}
This feature request is available on Nuxt.js community (#c74)
@ghost ghost added the cmty:feature-request label May 1, 2018
@paulgv
Copy link
Collaborator

paulgv commented May 1, 2018

Hi @metalanti
This can already be achieved by passing the translated slug to <nuxt-link>, it might look something like this (not necessarily the best way but it should give you some pointers):

<template>
  <nuxt-link :to="localePath({ name: 'article-slug', params: { slug: myTranslatedSlug } })">
    article
  </nuxt-link>
</template>

<script>
export default {
  computed () {
    myTranslatedSlug () {
      const { locale } = this.$i18n
      if (locale === 'de') {
        return 'nachrichten'
      }
      return 'news'
    }
  }
}
</script>

@metalanti
Copy link
Author

thank you!
so it's a solution,
but the Lang switcher with switchLocalePath won't work this way

I think if my request can be done, it would be more elegant :)

@ptdev
Copy link

ptdev commented Jul 24, 2018

I think this is exactly what I was asking here

Right now, we can place pretty much all other content that's to be translated in some external file or backend. The only missing strings are exactly the urls.

@paulgv If there's any way to have the component's nuxtI18n property have access to data fetched on asyncData before the router generation that would be great! I'm assuming they have to be hardcoded so you can use acorn at build time to create the router (?)

@metalanti did you ever find some way to accomplish what you were asking initially?

@metalanti
Copy link
Author

@ptdev we have the same problem, but mine is not urgent. i have still no solution

@ptdev
Copy link

ptdev commented Jul 26, 2018

Hi @metalanti , my problem is also not really urgent. It's just one of those "would be great to have" features.
Thanks for replying though, cheers!

@furyscript
Copy link

Anyone have news on this issue?
I need really urgent this feature.

@urbgimtam
Copy link

urbgimtam commented Mar 19, 2019

I'm also searching for an update on this issue.

@praffn
Copy link

praffn commented Apr 25, 2019

I'm chiming in here too, can't for the life of me figure out an elegant solution.

@stale
Copy link

stale bot commented Jun 24, 2019

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.

@danivaan
Copy link

danivaan commented Jul 1, 2019

bump

paulgv added a commit that referenced this issue Jul 1, 2019
Adds support for translating dynamic route parameters via the Vuex store module

BREAKING CHANGE: `preserveState` is now set automatically when registering the store module and
cannot be set via the configuration anymore

close #79
paulgv added a commit that referenced this issue Jul 1, 2019
Adds support for translating dynamic route parameters via the Vuex store module

BREAKING CHANGE: `preserveState` is now set automatically when registering the store module and
cannot be set via the configuration anymore

close #79
paulgv added a commit that referenced this issue Jul 1, 2019
Adds support for translating dynamic route parameters via the Vuex store module

BREAKING CHANGE: `preserveState` is now set automatically when registering the store module and
cannot be set via the configuration anymore

close #79
paulgv added a commit that referenced this issue Jul 1, 2019
Adds support for translating dynamic route parameters via the Vuex store module

BREAKING CHANGE: `preserveState` is now set automatically when registering the store module and
cannot be set via the configuration anymore

close #79
@paulgv
Copy link
Collaborator

paulgv commented Jul 1, 2019

Here's my attempt at supporting dynamic parameters translation in nuxt-i18n: #345

Please read the PR description to see how you can try it yourselves. I'd love to have some feedback on this!

paulgv added a commit that referenced this issue Jul 4, 2019
Adds support for translating dynamic route parameters via the Vuex store module

BREAKING CHANGE: `preserveState` is now set automatically when registering the store module and
cannot be set via the configuration anymore

close #79
paulgv added a commit that referenced this issue Jul 13, 2019
Adds support for translating dynamic route parameters via the Vuex store module

BREAKING CHANGE: `preserveState` is now set automatically when registering the store module and
cannot be set via the configuration anymore

close #79
paulgv added a commit that referenced this issue Jul 13, 2019
* feat: Dynamic route parameters translation

Adds support for translating dynamic route parameters via the Vuex store module

BREAKING CHANGE: `preserveState` is now set automatically when registering the store module and
cannot be set via the configuration anymore

close #79
paulgv added a commit that referenced this issue Jul 15, 2019
* feat: Dynamic route parameters translation

Adds support for translating dynamic route parameters via the Vuex store module

BREAKING CHANGE: `preserveState` is now set automatically when registering the store module and
cannot be set via the configuration anymore

close #79
paulgv added a commit that referenced this issue Jul 20, 2019
* feat: Dynamic route parameters translation

Adds support for translating dynamic route parameters via the Vuex store module

BREAKING CHANGE: `preserveState` is now set automatically when registering the store module and
cannot be set via the configuration anymore

close #79
@paulgv paulgv closed this as completed in 2d1d729 Jul 20, 2019
@katerlouis
Copy link

Any news?
Also looking for dynamic route paths translation.

The proposed solution to pass a function to paths: is what I had in mind aswell.
Rookie here, though... so I don't know if it's possible to expose context, i18n etc. to this function under the hood.

@Pezhvak
Copy link

Pezhvak commented Oct 13, 2023

This can't do much, since it's compile time micro and cannot be useful when loading data from an API.

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

9 participants