Reputation: 1118
I'm trying to translate something like this "User {id} payments"
to both English and Hungarian. How can I do it with the t macro with my current setup?
title: (id, i18n) => t(i18n)`userPayments`,
Upvotes: 0
Views: 615
Reputation: 1118
The solution in my case was:
18n._({
"userPayments",
message: "User {id} payments",
values,
});
Where values
is: { id: payment.id }
.
Upvotes: 1
Reputation: 305
The t
macro does not support variables. You should try using <Trans />
which supports variables and can be helpful in your case.
Here is an example code
// strings.json
"user_id": "User {{id}} payments"
const id = "123"
<Trans i18nKey={"user_id"} values={{id}} />
// output
"User 123 payments"
There are more options here depending on your setup, check https://react.i18next.com/latest/trans-component
Upvotes: 0