Open Lukasz-pluszczewski opened 5 months ago
The workaround with variable translation is not perfect, as the type of translated.foo
is string instead of a function when the translation function does not return a string:
const translations = {
foo: () => ({
'en_US': <div>Foo</div>,
'pl_PL': <div>Fuu</div>,
}),
}
translated.foo() // TS2349: This expression is not callable. Type String has no call signatures.
This hack works, but it's not pretty
const translations = {
foo: () => ({
'en_US': (<div>Foo</div>) as unknown as string,
'pl_PL': (<div>Fuu</div>) as unknown as string,
}),
}
translated.foo() // works as expected
Is your feature request related to a problem? Please describe. When the translation is JSX (see below), it works fine but validation here logs an error as if the translation is missing.
To avoid the warning you can create a variable translation like this:
Describe the solution you'd like JSX seems to work fine, so I would suggest allowing JSX translations and:
React.isValidElement()
function).