question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

{{ $t('key') }} dies

See original GitHub issue

I am not able to use $t in any view. Looks like a Bug.

TypeError: Cannot read property '_t' of undefined
    at Proxy.Vue.$t (vue-i18n.esm.js:178)
    at Proxy.render (app.vue?./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options:24)
    at VueComponent.Vue._render (vue.esm.js:3545)
    at VueComponent.updateComponent (vue.esm.js:4063)
    at Watcher.get (vue.esm.js:4476)
    at new Watcher (vue.esm.js:4465)
    at mountComponent (vue.esm.js:4070)
    at VueComponent.Vue.$mount (vue.esm.js:9047)
    at VueComponent.Vue.$mount (vue.esm.js:11941)
    at init (vue.esm.js:3124)
// app.js

import Vue from 'vue';

// use
import VueI18n from './vue-config-i18n.js';
Vue.use(VueI18n);
...

new Vue({
	el: '#app',
	template: '<app/>',

	// Register App Component
	components: {
		app: App
	}
});
// vue-config-i18n.js
import VueI18n from 'vue-i18n';

import lang_de from '@/lang/de.json'; // gets imported.

export default {
	install (Vue, options) {

		Vue.use(VueI18n);

		let i18n = new VueI18n({
			locale: 'de',
			fallbackLocale: 'de',
		});

		(async ()=>{
			let lang = 'de';
			
			//let msgs = await import('@/lang/'+lang+'.json');
			let msgs = lang_de;

			if (msgs) {
				i18n.setLocaleMessage(lang, msgs.default || msgs);
				i18n.lang = lang;

				console.log('i18n loaded lang', lang);
			}
			else {
				console.warn('i18n did not load lang', lang);
			}
		})();
	}
}
// app.vue
<template>
  <div>
    {{ $t('hello') }}
  </div>
</template>
// ./lang/de.json
{
	"hello": "Hallo Welt"
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
beau-gossecommented, Nov 21, 2019

FWIW the module approach doesn’t seem to work. The setup that worked for me (with Vue CLI) is instantiating VueI18n inside main.js.

// main.js
import Vue from 'vue'
import VueI18n from 'vue-i18n'

Vue.use(VueI18n)
const messages = {
  en: {
    message: {
      hello: 'hello world'
    }
  }
}

const i18n = new VueI18n({
  locale: 'en', // set locale  
  messages
})

new Vue({
  i18n,
  render: h => h(App)
}).$mount('#app')
0reactions
BananaAcidcommented, Oct 21, 2019

@kazupon so you say, the module is not compatible to the Vue’s default method of Vue.use(..plugin..) ? As I did show above (app.js) what I tried. What ever $mount is for, is does not match the vue guide. I would not have asked, and would not be the only one having trouble, if the vue-i18n docs would be crystal clear on this.

Could you please at least consider explaining the difference to why it is not like in the guide? I might then be able to adapt your code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Key Dies, Inc: Steel Rule Dies
Key Dies has the technical craftsmanship and technology to manufacture high quality and accurate steel rule dies and related tooling for your die...
Read more >
What To Do When Your Toyota Smart Key Dies
If your Toyota Smart Key dies, don't panic. Our Toyota dealer near Pasadena will tell you just how to unlock and start your...
Read more >
These Tricks Will Save You When Your Key Fob Dies
Don't panic if your key fob dies and you don't have a replacement battery. These little-known methods will get you back on the...
Read more >
What to Do When Your Key Fob Dies - MotorBiscuit.com
Key fobs can last a long time on a small battery, but they will eventually die, leaving us all in a pickle. As...
Read more >
Key Fob Dead? Push Button Start Car Won't?? Can't Get In ...
A dead battery in the remote control, smart key, intelligent key, key fob, you're in the right place! Never a charge to use,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found