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.

Use $t function outside template

See original GitHub issue

Hi,

I’m trying to do simple alert( $t('error') ) in my JavaScript file but $t is undefined. I’ve also tried Vue.$t but it is also undefined.

Is there any way to use the $t function outside a template ?

Thank you, clem.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

37reactions
asvaecommented, Oct 26, 2017

You can access translator globally like this:

import Vue from 'vue'

Vue.t('your.translation')
7reactions
po5icommented, Feb 16, 2018

I figured it out like this comment at issue #149

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue i18n-$t undefined outside template - Stack Overflow
What I want is to change title using $t but when I do title:"$t('dash.pone')", I get $t not defined. How can I make...
Read more >
Use $t function outside template #17 - Issuehunt
Hi,. I'm trying to do simple alert( $t('error') ) in my JavaScript file but $t is undefined. I've also tried Vue.$t but it...
Read more >
Do you write the functions that aren't used in <template ...
I used to write ALL my functions inside methods: , even the functions I weren't using inside <template> . What about you?
Read more >
Explicit (full) template specialization - cppreference.com
Explicit specialization may be declared in any scope where its primary template may be defined (which may be different from the scope where...
Read more >
Templates, C++ FAQ
My template function does something special when the template type T is int or std::string ; how do I write my template so...
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