0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Nuxt3のi18nの中でタグを使う

Last updated at Posted at 2023-12-25

はじめに

Nuxt3で

<div><a href="/registration">登録画面</a>に移動</div>
<div>Move to <a href="/registration">Registration</a></div>

みたいなリンクの多言語化をしようとしたときに

<div>
  <NuxtLink :to="/registration">
    {{ t('registration') }}
  </NuxtLink>
  {{ t('moveTo') }}
</div>

とすると英語と日本語で語順が違ったりして困っていました(調べてもNuxt2のやり方だったり、v-htmlを使ったり)。

いろいろ調べた結果、解決方法が分かったので残しておきます。

結論

i18n-t を使う。

.vueファイル

<i18n-t  tag="div" keypath="moveTo">
  <template #registrationLink>
    <NuxtLink to="/registration">
      {{ t('registration') }}
    </NuxtLink>
  </template>
</i18n-t>

言語ファイル(ja)

{
  "moveTo": "{registrationLink}に移動",
  "registration": "登録画面"
}

言語ファイル(en)

{
  "moveTo": "Move to {registrationLink}",
  "registration": "registration"
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?