nuxt3 icon indicating copy to clipboard operation
nuxt3 copied to clipboard

translation in single file component <i18n></i18n> doesn't work

Open salomonsanz opened this issue 3 years ago • 2 comments

Translation in single file components doesn't work for me.

<template>
    <div>
      {{ $t('hello', {name:'Peter'}) }}</div>
    </div>
</template>

<i18n>
{
  "en": {
    "hello": "Hola {name}"
  },

  "es": {
    "hello": "Hello {name} "
  }
}
</i18n>

Also I have tried with: <i18n src="~/locales/common.json"></i18n>

But it didn't work for me either...

Has anyone been able to get it to work?

My environment: Node 18.7.0 "@intlify/nuxt3": "^0.2.3" "nuxt": "3.0.0-rc.6"

salomonsanz avatar Aug 09 '22 14:08 salomonsanz

Have you tried it using local variables?

<template>
    <div>
      {{ t('hello', {name:'Peter'}) }}</div>
    </div>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
</script>

<i18n>
{
  "en": {
    "hello": "Hola {name}"
  },

  "es": {
    "hello": "Hello {name} "
  }
}
</i18n>

rr-denis-inozemtsev avatar Sep 02 '22 08:09 rr-denis-inozemtsev

I has the same problem, using const { t } = useI18n() works.

But how to use local messages without that two lines of code?

iBobik avatar Oct 24 '22 15:10 iBobik