Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
salomonsanz opened this issue Aug 9, 2022 · 2 comments
Open

Comments

@salomonsanz
Copy link

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"

@rr-denis-inozemtsev
Copy link

rr-denis-inozemtsev commented Sep 2, 2022

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>

@iBobik
Copy link

iBobik commented Oct 24, 2022

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants