3

I have a template which receive a message key when an event triggered.
I passed the "message.i.wanted" to the template, but the i18n is not translating based on the key I passed.
How should I updated my code so i18n can translate based on the key i passed?

<template>
      ...
      <v-card-text>{{ $t("messageKey") }}</v-card-text>
      ...
</template>

<script>
  import EventBus from "@/eventbus/eventbus.js"

  export default {
    name: "DialogBox",
    data() {
      return {
        messageKey: ""
      }
    },
    methods: {
      popUpDialog(message) {
        console.log("message dialog " + messageKey);
        this.messageKey = messageKey;
      }
    },
    mounted: function () {
      EventBus.$on("showMessageDialog", (messageKey) => {
        this.popUpDialog(messageKey);
      });
    }
  }
</script>


//en.json
{
  "messageKey": "Hello world",  // this was translated on the page
  "message.i.wanted": "message I wanted"
}

ref: https://kazupon.github.io/vue-i18n/

ttppbb
  • 65
  • 8
brian661
  • 538
  • 3
  • 11
  • 31
  • 2
    I don't know Vue i18n but at a guess, try `$t(messageKey)` without the quotes – Phil Sep 13 '19 at 02:43
  • @Phil Thanks, You are correct! Looks this is just a basic vue syntax, so I cannot find even I read the i18n doc... – brian661 Sep 13 '19 at 03:01

0 Answers0