nuxt.config.js is just a pure object for initializing nuxt, it's not included in lifecycle of vue instance, so basically you cannot use any vue plugin in it.
If you want to use different data inside it, I suggest you use tool like dotenv or node-config to load different variable by param (such as: locale)
// dotenv
require('dotenv').config({path: '/en'})
//data is in process.env
// node-config
const config = require('config');
config.get('EN')
But locale definition depends on complex conditions like cookies, local storage. What if wrap this data into callbacks and run it after all plugins?
Yes, it's ok, put i18n key into data and take out the translated text in plugin.
Not quite understand your suggestion, sorry. Lets consider an example:
// nuxt.config.js
module.exports = {
moduleConfig: {
defaultTitle: 'a.translation.key'
},
plugins: [
'~/plugins/i18n'
]
}
// i18n.js
export default ({ app }) => {
//
}
I need to get option in plugin and put it back after translation?
If you wan to translate configurations which are used in building, you cannot use plugin way, because plugins is executed in vue initialization after the building.
But if you want to translate configs which are use in rendering, plugin is a good choice, but this is not necessary to define custom configs in nuxt.config.js.
Can you describe you specific use case ?
I use OneSignal nuxt module, which has an options in nuxt.config. And some of this options needs to be translated
xref nuxt-community/pwa-module#16
@Darkside73 are you sure you need to put translatable strings in there? https://github.com/nuxt-community/pwa-module#-onesignal-module Onsignal options doesn't seem to specify that kind of casuistic.
See https://documentation.onesignal.com/docs/customize-permission-messages#section-customize-fullscreen-permission-message for example
what about writing your own module that fetches your current lang/locale and complements @nuxtjs' official oneSignal module?
just had a great setup experience with nuxt-i18n module for nuxt. it wraps vue-i18n.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.