You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following use case: i receive some abstract codes from my backend and each one has a specific message attached, so I wanted to do this:
// messages...
"items": {
"code_1": "message for item with code code_1",
//...
"code_N" "message for item with code code_N"
}
// ...then translate
t(`items.${item.code}`)
My problem now is that some of these messages are going to be vastly different, while others might be very similar with the exception of some numbers, so I wanted to have the possibility of reusing an existing message via the linked messages / @: syntax and also interpolating at the same time. The desired scenario would be something similar to:
// messages...
"items": {
"common_message": "Common message with {interpolated} value"
"code_1": "message for item with code code_1",
//...
"code_42": "@:{'common_message`}{ interpolated = 'foo'}" // This syntax is made up and unsupported, I know
// ...
"code_N" "message for item with code code_N"
}
// ...then translate, but without sending params here!!
// These all should result in the same: "Common message with foo value"
t(`items.${item.code}`) // When item.code === 'code_42'
t('items.code_42')
// Using common + params should be equivalent too
t('items.common_message', { interpolated: 'foo' })
I don't want to pass the interpolated value when calling t, that is a dealbreaker for me as I will have to make a second config map where I store if each code uses the custom message or the common message and the value to interpolate.
I know there is no such syntax to support this using the @: notation, and I also tried to do it using message functions, but seems like the linked helper cannot pass parameters so the interpolation "slot" results empty:
"items": {
"code_42": ({ linked }) => linked('items.common_message', { interpolated: 'foo' }) // This doesn't work either, produces "Common message with value"
}
Does anyone have any idea how to do this (if possible?). Thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!,
I have the following use case: i receive some abstract codes from my backend and each one has a specific message attached, so I wanted to do this:
My problem now is that some of these messages are going to be vastly different, while others might be very similar with the exception of some numbers, so I wanted to have the possibility of reusing an existing message via the linked messages /
@:
syntax and also interpolating at the same time. The desired scenario would be something similar to:I don't want to pass the interpolated value when calling
t
, that is a dealbreaker for me as I will have to make a second config map where I store if each code uses the custom message or the common message and the value to interpolate.I know there is no such syntax to support this using the
@:
notation, and I also tried to do it using message functions, but seems like thelinked
helper cannot pass parameters so the interpolation "slot" results empty:Does anyone have any idea how to do this (if possible?). Thanks!
Beta Was this translation helpful? Give feedback.
All reactions