Skip to content

Should I use $t() or t()? (same for $d/d, $n/n) #2191

Answered by absidue
opack asked this question in Q&A
Discussion options

You must be logged in to vote

$t() only uses messages and the locale from the global composer instance, whereas t() returned by useI18n() depends on the options passed to useI18n(), so it can be either use the global composer instance or local/component specific composer instance.

So if you want to use component specific messages or change the locale in one component without doing it for all, then you'll want to use the useI18n() approach. If you only use global stuff you can pick whichever style you like best.

Footnote: $t() is injected through Vue's app.config.globalProperties, which according to this vuejs/core#13360 won't be supported in vapor mode (vapor mode is unreleased so things may still change), so if you a…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@opack
Comment options

Answer selected by opack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants