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.

Access to vue-i18n assets is not available within a Vue component method when called via a Promise

See original GitHub issue

vue & vue-i18n version

vue v2.3.4 vue-i18n v7.0.3 Using with Laravel 5.4, and bundling assets with Webpack via Laravel Mix.

Reproduction Link

(Pending, will update post upon completion.)

Steps to reproduce

  • Prepare a Vue component, with Vue-i18n included as an asset on the top-level Vue instance
  • Prepare a Vue component, which includes a Vue method that accesses this.$t or this.$tc within the method. The method should not be defined using ES6 arrow notation so that the ‘this’ context is the Vue instance.
  • Call the method as the response or error method from a JS Promise

What is Expected?

Access to this.$t is provided via the ‘this’ binding solution provided by Vue

What is actually happening?

vue-i18n is not available (VueComponent property ‘_i18n’ is null). Other Vue instance properties are available in this context, such as this.$store when using vuex, as well as all component data, props and computed properties via ‘this’. An attempt to access this.$t generates an error: TypeError: Cannot read property '_t' of null Error is generated here, though the source cause is external of this: https://github.com/kazupon/vue-i18n/blob/9ef7b798e3c1d58dfae4f25e5e6b8c488b86d819/dist/vue-i18n.js#L111

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:40 (4 by maintainers)

github_iconTop GitHub Comments

119reactions
hunterliu1003commented, Dec 12, 2018

I having the same issue, use this.$root.$t() in promise works for me

8reactions
AlexandreBonaventurecommented, Apr 5, 2018

Can we reopen this ? I experienced the same error when using $t('xxx') inside a watcher callback. version: vue-i18n@7.4.2

As a workaround I stored the value outside the callback…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Access to vue-i18n assets is not available within a ...
Access to vue-i18n assets is not available within a Vue component method when called via a Promise #184. SirLamer posted onGitHub.
Read more >
Problem to use VueI18n outside a component
i18n.translate('str'), but when I call this occurs an error Cannot read property 'translate' of undefined. I'm using the following configuration.
Read more >
Composition API
The Composer instance provides a translation API such as the t function, as well as properties such as locale and fallbackLocale , just...
Read more >
The Ultimate Vue Localization Guide
Dive into Vue localization and learn how to plug the Vue I18n library into your app, so you can make it accessible to...
Read more >
How to Load i18n Locales Asynchronously in Vue 3 + Vite
All currently available locales are listed under the availableLocales property of the Vue I18n instance. If the selected locale is not included in...
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