6👍
✅
Another two options. Not very elegant, but not private api and is not slow.
-
Number one, define your own ugettext_lazy:
from django.utils import translation def ugettext_lazy(str): t = translation.ugettext_lazy(str) t.message = str return t >>> text = ugettext_lazy('Yes') >>> text.message "Yes" >>> activate('lt') >>> unicode(text) u"Taip" >>> activate('en') >>>> unicode(text) u"Yes"
-
Number two: redesign your code. Define untranslated messages separately from where you use them:
gettext = lambda s: s some_text = gettext('Some text') lazy_translated = ugettext_lazy(text) untranslated = some_text
👤Ski
7👍
This is the better version of your second solution
from django.utils import translation
the_string = ugettext_lazy('the content')
with translation.override('en'):
content = unicode(the_string)
- Is it ok to catch and reraise an exception inside Django transaction.atomic()?
- Nested field serializer – Data missing
1👍
You can do that (but you shouldn’t):
the_string = ugettext_lazy('the content')
the_string._proxy____args[0]
- Rendering a ReportLab pdf built from SimpleDocTemplate
- Django-ajax-selects example usage
- ValueError: Field 'id' expected a number but got 'Processing'
- Prettier vscode extension not support Django template tags {% tag %}
- Django reverse to contains/icontains
Source:stackexchange.com