Set @nuxtjs/i18n options from module
I'm trying to use the latest @nuxtjs/i18n on a module and I'd like it to already set the default i18n options and locales for the project using this module.
Is there a way to make it work without declaring locales again in the playground nuxt.config.ts?
I created an reproduction here:
https://stackblitz.com/edit/github-5akuzomv?file=playground%2Fapp.vue,playground%2Fnuxt.config.ts%3AL3
#i18n
StackBlitz
Nuxt - Starter - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
3 Replies
Hi @dine. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To answer your question about setting @nuxtjs/i18n options from a module in Nuxt, I'll refer to the relevant information from the provided knowledge sources.
Based on the information available, it appears that you can set the i18n options in your module's configuration. However, the exact method for doing this from within a custom module is not explicitly covered in the provided knowledge sources.
That being said, we can infer a possible approach based on how Nuxt configuration generally works:
1. In your module's setup function, you could extend the Nuxt configuration to include the i18n options. This would typically be done using the
extendConfig
method or by directly modifying the nuxt.options
object.
2. Your module could set default i18n options, which the main project could then override if needed.
Here's a conceptual example of how this might look in your module:
However, it's important to note that this approach is not explicitly documented in the provided sources, and there might be nuances or best practices specific to @nuxtjs/i18n that are not covered here.
For the most accurate and up-to-date information on configuring @nuxtjs/i18n from within a module, I recommend checking the official @nuxtjs/i18n documentation or reaching out to the module's maintainers directly.
Stack Overflow: Nuxt 3 i18n browser detection not working provides some insights into i18n configuration, but it doesn't specifically address setting options from within a module.
If you need more specific guidance, you might want to consult the Nuxt module development documentation or the @nuxtjs/i18n GitHub repository for advanced usage scenarios.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@607564534684844059> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Tried to set them using
nuxt.options
but it also doesn't work: https://stackblitz.com/edit/github-5akuzomv?file=playground%2Fnuxt.config.ts,src%2Fmodule.ts%3AL42StackBlitz
Nuxt - Starter - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.