Reputation: 1936
I'm using the VuePress framework to build a multilingual website for my project. The Internationalization Guide in the VuePress docs is quite helpful, but it doesn't explain, how to translate custom Vue.js components in the .vuepress/components/
directory.
From what I gathered, the best solution would be to integrate the vue-i18n plugin with VuePress, but there appears to be no guidance on how to do that?
Upvotes: 1
Views: 732
Reputation: 1936
This might not be the perfect solution, but it works as intended:
npm i vue-i18n
.mkdir ./.vuepress/theme/
.index.js
file to the newly created theme directory:// .vuepress/theme/index.js
module.exports = {
extend: '@vuepress/theme-default' // extend the default VuePress theme
}
enhanceApp.js
file which allows you to do some App Level Enhancements:// .vuepress/theme/enhanceApp.js
import VueI18n from 'vue-i18n'
export default ({ Vue, options }) => {
Vue.use(VueI18n);
options.i18n = new VueI18n({
locale: 'en',
});
}
$lang
:// .vuepress/components/Foo.vue
export default {
mounted() {
this.$i18n.locale = this.$lang;
},
i18n: {
messages: {
'en-US': { title: 'Foo' },
'de-DE': { title: 'Bar' }
}
}
};
I found no simple solution to hook into the root component to set the current locale globally. Maybe someone else has a hint on how to achieve this nicely?
Upvotes: 2