ttag
ttag copied to clipboard
nggettext and msgid returning ${ undefined } on plural
A string such as
const result = c('Title').ngettext(msgid`Delete ${name}`, `Delete ${count} contacts`, count);
when translated will result in
${undefined} Kontakte löschen
It seems that variables aren't replaced in the plural version
I've created a reproducible example here: https://github.com/mmso/ttag-bug-example/commit/5a550ddf1aceeb44f4c39c42879e152146145622
Thanks for the report! will try to fix that ASAP
I ran into something that I think might be a similar issue, so just detailing what I found in hopes that it is helpful.
In my codebase, I had two strings with the same key -- one had plural forms and the other did not.
e.g.
ngettext(msgid`${experience} XP`, `${experience} XP`, experience)
vs
t`${experience} XP`
The singular form existed first, and was all that was included in the extracted PO files (even after the plural was added). Even when the singular form was removed, the po files were not updated. Using said translation seemed to cause a runtime error with ngettext
+ r.replace
when it was used.
By deleting the singular form from all the translated versions and regenerating, I was able to get past this.
Not sure if that's helpful, but the singular/plural split seems like it might be related here.
We can see that the issue is replaceVariables takes variables only from first string (that is wrapped with msgid
):