nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.75k stars 483 forks source link

tc not exposed by the composable useI18n() #3136

Closed Wuraim closed 1 month ago

Wuraim commented 1 month ago

Environment


Reproduction

You just have to notice that the keys 'tc' of the object returned by useI18n() is not declared.

Describe the bug

When using the composable useI18n() to get access to the tc method for the pluralization, that function is not defined. (Unlike the function t, which is defined)

image

We are forced to use the $tc or other methods to do it

Additional context

No response

Logs

No response

github-actions[bot] commented 1 month ago

Would you be able to provide a reproduction? 🙏

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a couple of templates for starting with a minimal reproduction: 👉 [Reproduction starter (v8 and higher)](https://stackblitz.com/fork/github/BobbieGoede/nuxt-i18n-starter/tree/v8) 👉 [Reproduction starter (edge)](https://stackblitz.com/fork/github/BobbieGoede/nuxt-i18n-starter/tree/edge) A public GitHub repository is also perfect. 👌 Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve)
BobbieGoede commented 1 month ago

Did you update vue-i18n to v10? Nuxt i18n v8 does not support this version, but vue-i18n removed tc among other breaking changes, please refer to the documentation for more details on this https://vue-i18n.intlify.dev/guide/migration/breaking10.html.

slucas-elsa commented 1 month ago

I can't understand what your solution may be :

BobbieGoede commented 1 month ago

Sorry if my previous message was confusing. The tc function is only available as legacy API in vue-i18n v9, and has been fully replaced with an oveload of t in vue-i18n v10.

If you're using composition API, that means you likely don't want to use the legacy API, refer to this section to see a mapping of their equivalents: https://vue-i18n.intlify.dev/guide/advanced/composition.html#mapping-between-vuei18n-instance-and-composer-instance and this section on pluralization using the t function: https://vue-i18n.intlify.dev/guide/advanced/composition#pluralization.

Basically, this is not a bug, the API has changed. If you're still experiencing issues you will have to provide more information about your project and preferably a minimal reproduction.

EDIT - I just noticed the comment was not by the original author, but the information is applicable to both

slucas-elsa commented 1 month ago

Thanks a lot for your detailed answer, I understand now.

coremyslo commented 1 month ago

What took me some effort to realize is that when migrating from $tc to the new $t, you need to swap the 2nd and 3rd arguments:

$tc('banana', 100, { n: 'too many' })

should become:

$t('banana', { n: 'too many' }, 100)

However, the two-argument syntax remains unchanged:

$tc('apple', 100)

becomes:

$t('apple', 100)