-
Notifications
You must be signed in to change notification settings - Fork 15
Description
I programmatically build up TranslationStrings based on what the content of the message should be. (A common pattern when building up for example an error message based on several conditions to be displayed somewhere like a flash message in Pyramid.) Something like
message = _('phrase1', mapping={....})
if a:
message += _('phrase2 $b')
else:
message += _('phrase3 $b')
if b:
message += _('phrase4', mapping={....})
return message # Be able to apply a mapping to the appended TranslationString, to map $b above
This doesn't work when I pass it to Pyramid code for translation because by the time I've appended the TranslationStrings to each other it's already a string before it reaches Pyramid. If TranslationStrings are appended to each other it would be good if they would be retained as some kind of compound TranslationString where running the translate function on it would allow each of the sub-TranslationStrings to translate themselves from the .mo files. And to be able to apply a mapping to the compound TranslationString (the last line above) or to each TranslationString that makes it up.
The only alternatives I see to this solution are messy. Either I return several message parts to Pyramid, like return (message1, message2, message3, message4, ...). Or each condition above has the full message, like below, which would lead to repetitive code and also duplication of effort by translators.
if a:
message = _('phrase1 phrase2 phrase4')