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

feat: support generated locale type #1890

Merged

Conversation

BobbieGoede
Copy link
Member

@BobbieGoede BobbieGoede commented Jul 14, 2024

While figuring out unplugin-vue-router generates and uses its types I figured a similar approach could be used here.

This PR adds the IntlifyGeneratedTypeConfig interface which is empty by default, and a GeneratedLocale type which resolves to never if IntlifyGeneratedTypeConfig['locale'] remains unset. Maybe it should be renamed to just GeneratedTypeConfig or TypeConfig 🤔

I have updated nuxt-modules/i18n#3025 to use this approach, please try it out locally to see if it works for you locally. I'm not very experienced with types like these, just trying to imitate what seems to work for other libraries, maybe there's a better approach?

For reference, the types used in router van uvr:

When this interface is augmented like below, the Locale type will resolve to "en" | "en-GB" | "ja" | "fr" | "nl" | "de" everywhere, leaving the interface empty (no augmentatio) will use the types normally and Locale resolves to string.

declare module '@intlify/core' {
  // generated based on configured locales
  interface IntlifyGeneratedTypeConfig { 
    locale: "en" | "en-GB" | "ja" | "fr" | "nl" | "de"
  }
}

@BobbieGoede
Copy link
Member Author

Looks like the type tests fail, will look into this

@kazupon kazupon added the Type: Feature Includes new features label Jul 15, 2024
Copy link
Member

@kazupon kazupon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Job! ❤️
I always appreciate your PR!
I have tested it locally and your PR works as expected !!

I would mind you to fix two things: 🙏

  • change IntlifyGeneratedTypeConfig to GeneratedTypeConfig
  • export GeneratedTypeConfig also in petite-vue-i18n pkg.

when you will fix these, we can merge your PR :)

@BobbieGoede
Copy link
Member Author

Great Job! ❤️ I always appreciate your PR! I have tested it locally and your PR works as expected !!

I would mind you to fix two things: 🙏

  • change IntlifyGeneratedTypeConfig to GeneratedTypeConfig
  • export GeneratedTypeConfig also in petite-vue-i18n pkg.

when you will fix these, we can merge your PR :)

I have implemented your suggestions 💪

Looks like the e2e tests for windows are failing, is this related to the code or flaky? (I can't rerun the action)

@kazupon kazupon merged commit 1643bb5 into intlify:master Jul 16, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Includes new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants