nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.76k stars 484 forks source link

feat: experimental typed routes #3142

Closed BobbieGoede closed 2 months ago

BobbieGoede commented 2 months ago

πŸ”— Linked issue

❓ Type of change

πŸ“š Description

[!IMPORTANT] Very experimental and relies on nuxt/router/uvr internals, this will not be backported to v8.

I'm not very happy with the implementation right now, but it does work... I think the demand/convenience of this feature somewhat justifies adding this albeit under an experimental flag.

We should communicate very clearly that this relies on internals of Nuxt, Vue Router and unplugin-vue-router, perhaps we can make the types fallback to original behavior on failure (maybe it already does). A proper implementation will likely require collaboration with the maintainers of those packages, we should not expect this to keep working as is.

This will need some documentation and basic tests so we know things fail if internals have changed.

Demo stackblitz project here: https://stackblitz.com/edit/bobbiegoede-nuxt-i18n-starter-srohiz?file=nuxt.config.ts&file=composables%2Ftest.ts

Demo of localePath autocompletion

https://github.com/user-attachments/assets/29d00cb6-1cdc-409f-bb23-fa08153d4a4e

Demo of custom routes configuration autocompletion and basic validation (prefix '/')

https://github.com/user-attachments/assets/38c41d9d-deb7-4688-be02-1ce0c18a9628

πŸ“ Checklist

pkg-pr-new[bot] commented 2 months ago

Open in Stackblitz

pnpm add https://pkg.pr.new/@nuxtjs/i18n@3142

commit: 352ce15

kazupon commented 2 months ago

Since it uses the vue-router type, it would be good if posva is able to review it.

@posva Can you review it ?, if you have the time πŸ™

BobbieGoede commented 2 months ago

@userquin If you see some obvious structural improvements, feel free to suggest them, the must be some way to leave out the augmentations in internal-global-types.d.ts πŸ€”