Describe the bug
You cannot use template strings with the t function:
t({message: `template`})
results in
msgid "undefined"
msgstr "undefined"
Expected behavior
msgid "template"
msgstr "template"
Additional context
Same occurs with defineMessage macro, what should we do here? @tricoder42
Thanks, Sergio. Just wanted to add this remark after trying to find a workaround using defineMessage :-)
The problem is that neither macro handles template string.
// This workds
t({message: t`template`})
// Also this
t({message: "template"})
// This doesn't work
t({message: `template`})
I'm already working on the fix. Meanwhile please use these workaround 鈽濓笍
Nice! Works for me :-)
It is is also not possible to use components for t function.
i18n._(
t({
id: 'testID',
components: [<a href="" />],
})
),
It this supposed to work? In documentation it is specified that t is equivalent for
@MartinCerny-awin This definitely isn't possible. t macro and the whole lowercase macros family only returns strings. You must use Trans and other capitalized macros if you want to use components.
t - function - strings only
Trans - React component - renders string or components
@tricoder42 I wonder if this behavior is as expected:
// src/that/file.ts
import {t} from '@lingui/macro'
// ...
const nonComponentFn = (error?: any, messageId?: string) => {
const helperText = error
? messageId
? t({id: messageId}) // this gets extracted as `undefined`
: t`error` // this gets extracted as expected
: undefined
return {helperText}
}
// ...
The idea is that someone can pass an id of translation to that function so we should translate it here
And, extracted output is
#: src/that/file.ts:24
msgid "undefined"
msgstr ""
AFAIU, such t calls should not be extracted
Yeah, you're right. It shouldn't get extracted. Would you like to send a PR? This could be easy but grateful fix
@tricoder42 sure, I'll take a look