Skip to content

reactive $t() in script? #934

Answered by Demivan
wbolster asked this question in Q&A
Apr 2, 2025 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi,

The return type of $t is a string, and yes, it cannot be reactive. But $t method itself is reactive, as you found out by using () => $t().

Having $t return Ref<string> would be less convenient, forcing .value usage everywhere.

computed(() => $t('...')) - this is not a workaround, but a normal use case.
Most of the time when you are in script setup you are already in some kind of computed context, and you can use $t directly.

For example, let's say that you want to add site name to your page titles:

useTitle(`${$t("loading")}-${site}`); // not reactive

Reactive result of $t will not help you in this case:

useTitle(`${$t("loading").value}-${site}`); // not reactive

So you are still forc…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by wbolster
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
Converted from issue

This discussion was converted from issue #933 on April 02, 2025 15:48.