A macro like pgettext!(catalog, "context", "msgid") could be made that would expand to catalog.gettext(concat!("context", "\x04", "msgid")). However, now we have two API styles: pgettext!(catalog, ...) and catalog.pgettext(...).
Change internal format
Index the internal translation dictionary by (msgid, context): (&str, Option<&str>). Get rid of \x04 past the parsing stage altogether. I am leaning towards this solution.
Catalog::pgettext
andCatalog::npgettext
allocate aString
on every call due to the need to form a key{context}\x04{msgid}
.The reference implementation of
gettext
solves this elegantly via a macro that concatenates the string literals at compile time.Possible solutions
Macros
A macro like
pgettext!(catalog, "context", "msgid")
could be made that would expand tocatalog.gettext(concat!("context", "\x04", "msgid"))
. However, now we have two API styles:pgettext!(catalog, ...)
andcatalog.pgettext(...)
.Change internal format
Index the internal translation dictionary by
(msgid, context): (&str, Option<&str>)
. Get rid of\x04
past the parsing stage altogether. I am leaning towards this solution.