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

Rename i18n:extend-messages to i18n:extendMessages #1942

Closed
kazupon opened this issue Mar 18, 2023 · 3 comments · Fixed by #1969
Closed

Rename i18n:extend-messages to i18n:extendMessages #1942

kazupon opened this issue Mar 18, 2023 · 3 comments · Fixed by #1969
Assignees
Labels
good first issue help wanted 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing PR Welcome v8

Comments

@kazupon
Copy link
Collaborator

kazupon commented Mar 18, 2023

          In that case, should I rename the existing `i18n:extend-messages` hook to be camel case as well?

Originally posted by @ineshbose in #1919 (comment)

@kazupon kazupon added help wanted good first issue v8 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing PR Welcome labels Mar 18, 2023
@kazupon kazupon changed the title Rename i18n:extend-messages to i18n:extendMessage Rename i18n:extend-messages to i18n:extendMessages Mar 18, 2023
@ineshbose
Copy link
Collaborator

Brilliant issue to get contributing to this repo! 😄

Copy link
Collaborator Author

kazupon commented Mar 25, 2023

We might be able to deplicate i18n:extend-message. Because I think we can do the same thing with the recently supported Layers. /cc @BobbieGoede

https://v8.i18n.nuxtjs.org/guide/layers

The reason for deprecated is that this hook pre-compiles the messages passed by vue-i18n at build-time, and generates code in i18n.options.mjs in the template.
This is javascript to javascript and not safe.
Also, if large messages are set in this hook, i18n.options.mjs will become large, resulting in a performance issue.

reference discord link:
https://discord.com/channels/1044887051155292200/1063952424764719154/1064230457098645645

@BobbieGoede
Copy link
Collaborator

@kazupon that should be possible, I can look into adapting for modules. Are there any advantages over extending messages with objects instead of files with the current approach?

Is there a preferred way of registering/discovering modules that want to provide messages/locales? Using a hook I figure it could work something like this for modules:

export default defineNuxtModule({
  async setup(options, nuxt) {

    // could potentially be simplified inside a function to handle resolve and hook
    const resolver = createResolver(import.meta.url)
    nuxt.hook('i18n:registerModule', registerI18nModule => {
      registerI18nModule({
        // paths may be more unpredictable compared to layers?
        langDir: resolver.resolve('./locales'),
        locales: [
          {
            code: 'en',
            iso: 'en-US',
            file: 'en.json',
            name: 'English'
          },
          {
            code: 'nl',
            iso: 'nl-NL',
            file: 'nl.json',
            name: 'Nederlands'
          }
       ]
    })
  }
)

I'm not sure if iso and name are relevant for adding messages from modules.

The discord link doesn't work for me so I am not sure what it references 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue help wanted 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing PR Welcome v8
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants