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: experimental vue-i18n and messages type generation #3151

Merged

Conversation

BobbieGoede
Copy link
Collaborator

@BobbieGoede BobbieGoede commented Oct 3, 2024

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This is a different, improved approach compared to BobbieGoede#50, that PR reimplemented the loading of configs and messages while this PR reuses the existing logic.

(Same demo video as BobbieGoede#50 as this should be functionally the same)

Code_2024-07-17_14-54-20.mp4

📝 Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

@BobbieGoede BobbieGoede self-assigned this Oct 3, 2024
Copy link

pkg-pr-new bot commented Oct 3, 2024

Open in Stackblitz

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

commit: ca91f96

@BobbieGoede BobbieGoede marked this pull request as draft October 3, 2024 20:00
@BobbieGoede BobbieGoede marked this pull request as ready for review October 3, 2024 20:31
@BobbieGoede BobbieGoede marked this pull request as draft October 3, 2024 22:04
@BobbieGoede BobbieGoede changed the title [DRAFT] feat: vue-i18n and messages type generation [DRAFT] feat: experimental vue-i18n and messages type generation Oct 3, 2024
@BobbieGoede BobbieGoede marked this pull request as ready for review October 3, 2024 22:32
src/module.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

I will leave a comment on the points that I am concerned about.

I integrated all the locale messages when I implemented i18n support first time for h3.
I noticed that all the locale messages are unnecessary on the server side, affecting performance.
Since this is experimental, I think this implementation is fine, but at some point, I think a mechanism that allows locale messages to be loaded only on the server side will be necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm I'm not entirely sure what you mean 🤔 Do you mean a mechanism to load a part/subset of messages?

I haven't checked if this does anything to a project production build, this should only be used in development so I should probably disable this functionality if not in dev mode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After looking into it, it looked like it was being included in production too 😅 Now this functionality should only be enabled (if configured) during development, this still has performance impact but not after building.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have added some options, the configuration now accepts false | 'default' | 'all':

  • false - disables type generation
  • 'default' - generate types based on configured defaultLocale
  • 'all' - generate types based on all configured locales

This way users can decide to only generate types using the defaultLocale resources, which prevents loading all locales unnecessarily.

@kazupon
Copy link
Collaborator

kazupon commented Oct 6, 2024

@BobbieGoede
Excellent work! 💯

I've wanted to implement a type generation like your PR, and I'm so happy you're supporting it!
Let's keep going!

@BobbieGoede BobbieGoede changed the title [DRAFT] feat: experimental vue-i18n and messages type generation feat: experimental vue-i18n and messages type generation Oct 6, 2024
@BobbieGoede BobbieGoede merged commit 4f73469 into nuxt-modules:main Oct 7, 2024
9 checks passed
@BobbieGoede BobbieGoede deleted the feat/generated-messages-types-2 branch October 7, 2024 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants