I created my custom translation plugin in which I extend Vue.
// Trans class here...
const translations = {}; // Need to fetch this json obj from server here
Vue.prototype._ = (key, params = {}) => {
return trans.get(key, params);
};
How can I prefetch it so Vue can use it?
Thanks!
Hi @vadimsg
What you can do is:
const translations = require('./path-to-default-lang.json');
This way, Webpack will put your translation object directly in your bundle.js and the translations variable will be filled and ready to use with Vue.
Otherwise, the middleware option that will come in an upcoming release will let you fill the translations object from the server-side (but also from the client-side if the user change the langage).
In my situation I need to fetch it from api.
Thanks, waiting for the release!
The middleware feature is out with the 0.9.8 release.
See the example with i18n.
Demo: http://i18n.nuxtjs.org/
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.
Most helpful comment
The middleware feature is out with the 0.9.8 release.
See the example with i18n.
Demo: http://i18n.nuxtjs.org/