<i18n-t> in slot won't get component's local messages
See original GitHub issueReporting a bug?
I’m migrating my project to Vue 3 and have issues with <i18n-t>
in slots (that I didn’t have with Vue 2).
Here is a component C1 with $t
and <i18n-t>
:
<template>
<span>C1:</span>
<div>{{ $t("hello", { world: $t("world") }) }}</div>
<i18n-t keypath="hello" tag="div">
<template #world>
<strong>{{ $t("world") }}</strong>
</template>
</i18n-t>
</template>
<script>
...
i18n: {
messages: {
en: {
hello: "Hello {world}",
world: "world!",
},
},
}
...
</script>
This outputs, as expected:
C1: Hello world! Hello world!
Now, here is the component C2:
<template>
<div>C2 slot: <slot></slot></div>
</template>
If I modify C1’s template like this (aka just move previous code to C2’s slot):
<template>
<C2>
<div>{{ $t("hello", { world: $t("world") }) }}</div>
<i18n-t keypath="hello" tag="div">
<template #world>
<strong>{{ $t("world") }}</strong>
</template>
</i18n-t>
</C2>
</template>
This outputs:
C2 slot: Hello world! hello
As you can see, $t
works as expected but not <i18n-t>
, it behaves like it doesn’t find the messages while $t
does (like they do not have the same scopes).
Expected behavior
Expected output:
C2 slot: Hello world! Hello world!
I expected <i18n-t>
to have the same scope as $t
, find the messages and show them instead of falling back to displaying the keypath.
I do not have this issue with Vue 2.
Reproduction
https://codesandbox.io/s/suspicious-sea-reu1e
System Info
npmPackages:
vue: ^3.2.14 => 3.2.14
vue-i18n: ^9.1.7 => 9.1.7
Screenshot
No response
Additional context
No response
Validations
- Read the Contributing Guidelines
- Read the Documentation
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
@semiaddict I’ve just released v9.1.8 Please check it! https://github.com/intlify/vue-i18n-next/releases/tag/v9.1.8
Happy coding! 😃
Thank you very much @kazupon. Would it be possible to add the fix on the 9.1.x version as well ? I think it was only applied to the 9.2.x, which is still in beta.