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.

How to use $t in a .js file?

See original GitHub issue

I have a filter.js file in which I store my Vue filters. I now need to translate some of the content, so basically I want to do something like this:

File: filters.js

import Vue from 'vue'

Vue.filter('my-filter', value => {
   return  `${value} ${$t('my-key')}`
});

Is it possible?

<div align="right">This question is available on Nuxt.js community (#c79)</div>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:15

github_iconTop GitHub Comments

21reactions
SuperTapircommented, Sep 13, 2018

You can try this export const $t = sign => Vue.prototype.$nuxt.$options.i18n.t(sign);

6reactions
Rackarcommented, Jul 23, 2021

An easy way to use in a completely separated JS file:

$nuxt.$t('hello')
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use $t in a .js file? · Issue #84 · nuxt-modules/i18n
I have a filter.js file in which I store my Vue filters. I now need to translate some of the content, ... Just...
Read more >
How to get i18next.t() in plain JS file? - Stack Overflow
You can import i18n instance from your i18n.js file, it contains t on it. import i18n from '../i18n'; i18n.t // <- use it....
Read more >
Including JavaScript In Your Page
To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute...
Read more >
Documentation - Type Checking JavaScript Files - TypeScript
In a .js file, the compiler infers properties from property assignments inside the class body. The type of a property is the type...
Read more >
Why won't .js files work in notepad++ - Codecademy
I have an html and a css file along with a script.js file all in the same folder. the html and css work...
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