Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dmitry
Created December 8, 2019 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry/ee8566ec493f703db8634f81d7386764 to your computer and use it in GitHub Desktop.
Save dmitry/ee8566ec493f703db8634f81d7386764 to your computer and use it in GitHub Desktop.
import merge from 'lodash.merge';
export default {
data() {
return {
translationMessageLoaded: false
};
},
created() {
if (!this.$root.i18nComponents) {
this.$root.i18nComponents = [];
}
if (!this.$root.i18nComponents.includes(this.componentName)) {
this.$root.i18nComponents.push(this.componentName);
this.loadTranslationMessages();
}
},
computed: {
componentName() {
return this.$options.name
.replace(/\.?([A-Z]+)/g, function (x,y){return "_" + y.toLowerCase()}).replace(/^_/, "")
.replace(/(_page|_layout)$/, '');
}
},
i18n: {
messages: {}
},
watch: {
translationMessageLoaded(a) {
if (a) {
this.$forceUpdate();
}
}
},
methods: {
async loadTranslationMessages() {
const locale = this.$i18n.locale;
const messages = (await import(/* webpackChunkName: "i18n-[request]" */ `src/i18n/${this.componentName}/${locale}.json`)).default;
this.$options.i18n.messages[locale] = merge(
this.$options.i18n.messages[locale],
messages
);
this.translationMessageLoaded = true;
}
},
render(createElement, children) {
// return this.$scopedSlots.default({})
// if (this.translationMessageLoaded) {
return createElement("div", ['test', children]);
// }
// else {
// return createElement("div", []);
// }
// return createElement(
// "div",
// [
// "This is a parent element",
// ...children,
// ],
// );
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment