question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<i18n-t> in slot won't get component's local messages

See original GitHub issue

Reporting 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kazuponcommented, Oct 4, 2021

@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! 😃

1reaction
semiaddictcommented, Oct 2, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component based localization | Vue I18n
As in the example above, if the component doesn't have the locale message, it falls back to globally defined localization info. The component ......
Read more >
Breaking Changes - Vue I18n
In Vue I18n v9 or later, it change to be using $tm or tm . The following Composition API example: // e.g. Array...
Read more >
The Ultimate Vue Localization Guide | Phrase
Note » If we don't explicitly set the scope="global" prop on the <i18n-t> component we will get a console warning reading, “[intlify] Not ......
Read more >
vue.js - How to stop i18n from reverting to default locale on ...
You could use localstorage to persist the information. In your store try to get appLanguage from the localStorage . export default new Vuex....
Read more >
Changelog - ViewComponent
Prevent polymorphic slots from calculating content when setting a slot. ... Fix issue causing helper methods to not be available in nested components...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found