Does not cascade translation
I've noticed that if I interpolate translated strings into translated strings - it doesn't work.
This happens something like this:
warning = _("Missing correct answers")
object_id = "fnord"
_("${warning} for object with id ${object_id}")
% dict(warning=warning, object_id=object_id))
This makes it really hard to use this in places where you do not controll what strings get spliced into a translated strings - which is really unfortunate.
To my understanding, interpolate() needs to check all strings it interpolates and call interpolate on them too as needed.
@wichert, do you have any idea how this could be fixed? Seems like @dwt stumbled upon this issue at least twice with no feedback yet.
The %-operator itself does work: that returns a new TranslationString instance with an updated mapping. The underlying issue is better described in #14: interpolate() does not check for TranslationString instances when inserting values. There are a three possible ways of fixing that:
- translation manually in your code, and passing the result as a (new) mapping to the translate call.
- have TranslationString.interpolate() check for TranslationString instances and do recursive translation
- update Translator.translator() to check the mapping for TranslationString instances, and translate those to create a new (translated) mapping)
The first option is cumbersome, but works today. The second option is impossible to implement: the interpolate method does not have access to the translation catalogs/policy, so it can't do the translation. The last option should be doable.
Thanks for the feedback, do you plan to do that or are you waiting for pull requests on this as you don't have time?
I'm planning to do it, but considering current priorities and available time it might be a while before I get to it.