Django: Two translations at once in template using i18n
Our company generates reports that often use a dual language format. For instance:
English Test Name / Chinese Test Name: Result cm
We have our translations already set and I have generated .po/.mo files and can do a single language without problem. However, is there a way, with builtin Django functionality, to do the dual language option. The current format for a template,
{% trans "Key" %}
leaves a little to be desired with what we are doing. Maybe
{% blocktrans %}
would be better?
My wanting to just throw logic at it wonders if there is a way to use
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
to get at the selected language and then manipulate the language that way somehow.
Any ideas beyond re-writing the Mi开发者_开发问答ddleware?
I'm not aware of how to do it inside of a template, but the i18n python framework has the ability to activate a language using django.utils.translation.activate
to activate a given language. A brief glance at the templatetags code for trans and blocktrans it appears there isn't anything like this implemented for the template tags, however you could write your own tags that wrap trans and blocktrans and allow you to specify a certain language as an argument.
精彩评论