You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exemplary lets imagine the route /products/[type] should generate the following routes:
- en: '/products/shoes'
- de: '/produkte/schuhe'
- fr: '/produits/chaussures'
But all localized slugs need to be mapped to a fixed value (most likely an enum), In this example this could be ProductType.Shoe.
To archive this we need three things:
1. Map localized param (slug) to enum
Locale + Slug -> Fixed value. Basically this is a reverse translation. E.g.:
- en: '/products/shoes' -> type is ProductType.Shoe,
- de: '/produkte/schuhe' -> type is ProductType.Shoe,
- fr: '/produits/chaussures' -> type is ProductType.Shoe,
- fr: '/produits/shoes' -> type is undefined (or throw error),
This is needed e.g. for making a fetch request to the API.
2. For the current route params, tell @nuxtjs/i18n about each other localized slug
This is needed for language switching. With the example above, the following needs to be generated:
3. Generate explicit links
When wanting to place a link, we need to get the localized slug for the current locale. E.g. with the example above, if the current locale is de then the following should be generated:
I dont have the time to get into @nuxtjs/i18n to implement this BUT I was thinking about how to solve this for some time now and I made a sandbox where I have a fully working example with the three needed functions. I dont know if this is the best possible way (if not PLEASE make suggestions!) but maybe this could be a good starting point for @nuxtjs/i18n contributors to implement this feature.
Describe the feature
Exemplary lets imagine the route
/products/[type]
should generate the following routes:But all localized slugs need to be mapped to a fixed value (most likely an enum), In this example this could be
ProductType.Shoe
.To archive this we need three things:
1. Map localized param (slug) to enum
Locale + Slug -> Fixed value. Basically this is a reverse translation. E.g.:
This is needed e.g. for making a fetch request to the API.
2. For the current route params, tell @nuxtjs/i18n about each other localized slug
This is needed for language switching. With the example above, the following needs to be generated:
3. Generate explicit links
When wanting to place a link, we need to get the localized slug for the current locale. E.g. with the example above, if the current locale is
de
then the following should be generated:Additional information
I dont have the time to get into @nuxtjs/i18n to implement this BUT I was thinking about how to solve this for some time now and I made a sandbox where I have a fully working example with the three needed functions. I dont know if this is the best possible way (if not PLEASE make suggestions!) but maybe this could be a good starting point for @nuxtjs/i18n contributors to implement this feature.
Sandbox Repo: https://github.com/MickL/nuxti18n-localized-slugs
Sandbox Stackblitz: https://stackblitz.com/~/github.com/MickL/nuxti18n-localized-slugs?file=app/pages/products/%5Btype%5D.vue
The text was updated successfully, but these errors were encountered: