`useLingui` should be "React friendly"
See original GitHub issueIs your feature request related to a problem? Please describe.
I want to have elements I could use anywhere in my code, so I do thing = <Trans>Hello</Trans>
, however sometimes I have to pass this as a string to placeholders and other things.
I could use Trans.render
to “renderProp” the message, but I would prefer useLingui._
to translate what I have into the string. Unfortunately that is returning [Object object]
Right now API exposed thought i18n
is friendly only to core
, not react
. Well, it is from core
.
Describe the solution you’d like
i18n._
from useLingui
or I18n
should understand that some values might be a React.Elements.
Describe alternatives you’ve considered Well, all I need is stored in the Trans`s props.
if (id.type === Trans) {
return i18n._(id.props);
}
Additional context
Technically, implementation of Trans
should be exposed to the end user, so one could call it without using Trans
itself.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:20 (14 by maintainers)
In v3 all js macros return translation, not an object:
I guess that solves your problem?
Why don’t you use
i18n._
here?There is no problem to provide instance. The problem is that all macros except
defineMessage
use imported global instance.Assume we have async safe
getI18n
which returns right i18n instance. It can be done with Continuation Local Storage.v2
—transformed—>
v3
—transformed—>
getI18n?
—>
Shallow variable declaration may work, but doesn’t play well with static analysis tools, because before transformation the variable isn’t used anywhere.
With new macros you meet the same issue as above. You consume i18n from context, but don’t use in explicit way.
v3
v2 like
it leaves no choice. For some existing applications migration to v3 becomes impossible, because you either loose ability to change language without loosing application state or have issues with stuck messages.