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.

Support Composition API

See original GitHub issue

Hello and first of all, thank you for this awesome plugin. Until today I was used to write this.$t('to_translate') in my script with the corresponding

<i18n>
  to_translate: "translated"
</i18n>

in my SFC file when, for example, I wanted to use notifications. Soon, with the Composition Api RFC, a new syntax will be introduced to develop our components. In fact, it’s already available with this plugin. So I was wondering what is the correct way of doing it with the new syntax as this is not available in the setup function and even if $i18n.t is accessible through setup context root, it seems that the I18n tag is not yet processed. I know that I could define translations inside the messages property at init or try to access the translation inside the onMounted() lifecycle hook but it feels kind of hacky. Any thoughts?

Issue Analytics

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

github_iconTop GitHub Comments

19reactions
kazuponcommented, Aug 27, 2019

Hi!

I have plans to rewrite vue-i18n functionality from full scratch with composition API and TypeScript in the next major version. I’ll keep the current vue-i18n API as compatible like the Vue object style API.

I’m developing some vue-i18n related tools (e.g. eslint-plugin-vue-i18n, vue-cli-plugin-i18n, and etc) and libraries (vue-i18n-locale-mesasge, vue-i18n-loader).

when I take a break these developing, I’ll try to start vue-i18n major version developing.

13reactions
snapwichcommented, Feb 9, 2020

If you’re using @vue/composition-api then the instance with your local component messages is available using getCurrentInstance.

e.g.

<i18n>
  {
    "en": {
      "localMessage": "Blah"
    }
  }
</i18n>

<template>
  <div>{{ message }}</div>
</template>

<script>
import { createComponent, ref, getCurrentInstance } from "@vue/composition-api";
export default createComponent({
  setup() {
    let vm = getCurrentInstance();
    let message = ref(vm.$i18n.t("localMessage"))
    return {
      message
    }
  };
})
</script>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Composition API FAQ - Vue.js
Composition API is a set of APIs that allows us to author Vue components using imported ... and provides a great development experience...
Read more >
Composition API plugin for Vue 2 - GitHub
@vue/composition-api supports all modern browsers and IE11+. For lower versions IE you should install WeakMap polyfill (for example from core-js package).
Read more >
Vue 3 Composition API: Basics and Patterns | by Arcana ...
A lot of Vue based frameworks such as Nuxt and Vuetify still rely on Options API and have no support for Composition API...
Read more >
Vue: Support for Composition API : WEB-41565 - YouTrack
Using https://github.com/vuejs/composition-api, one can use that API with Vue 2. Please add proper support for the new API. Note: Until the API design...
Read more >
Vue 3.2 - Using Composition API with Script Setup
Introduction Vue 3 introduced the Composition API as a new way to work ... improvements in IDE tooling support, we believe Composition API...
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