i18n: Vue-i18n-loader does not work
There is the problem in the main loader. In the documentation of vue-i18n, translations could be defined in the Single page component(<i18n></i18n>) by the following configs in the rule’s module:
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
i18n: '@kazupon/vue-i18n-loader'
}
}
},
// ...
]
}
The problem is that we don’t use ‘vue-loader’, we use ‘eslint-loader’ instead in nuxt project. And adding loaders into the config changes nothing. I tried to define new ‘push()’ with ‘vue-loader’, but after that, other loaders works incorrectly. Or maybe Vue-i18n-loader is not adaptive for the SSR, so maybe we need nuxt-i18n-loader. And is there a place to be?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (1 by maintainers)
Hello everybody, I have an alternative solution, if you are interested.
Explanation
The problem by adding the webpack configuration like below, is that you overwrite all of
vue-loaderrules set byNuxt.A simple
console.log()on thewebpackconfiguration:Solution
The simplest way it’s to add the configuration like below
Full Setup
Install
vue-i18nand@kazupon/vue-i18n-loader(in dev).package.jsonCreate
i18n.jsplugin.plugins/i18n.jsAdd plugin to Nuxt
nuxt.config.jsAdd
<i18n>in component/page/layout templatecomponents/MyComponentYou can see a sample on my repository: https://github.com/moifort/play-with-nuxt
Solution for nuxt 2:
I’m using nuxt-edge after upgrading to 5.1 I’m getting the following error:
TypeError: Cannot set property 'i18n' of undefined at Builder.extendBuild.config (/Users/chanlito/Codes/experimental/x-app/node_modules/nuxt-i18n/src/module.js:105:31)hi @adetbekov , here’s my package.json atm
here’s a part of my nuxt.config.js
here’s my vue-i18n.js
here’s a i18n part of a component :
and finally the results : https://i.imgur.com/F066MWU.png https://i.imgur.com/BYArnvq.png
In the nuxtServerInit, we have some logical to handle marketLanguage from the http request.
Let me know if you’re still having issues
@karellm I haven’t used vue-i18n-loader recently and don’t think I’ve ever tried with a lang switcher actually, the few times I used it was to make some quick prototyping before moving all translations to another file. But there are some issues with this option for sure, I still need to investigate but am lacking time lately…