我尝试翻译字符串,它位于mark_safe()函数中:
from django.utils.translation import ugettext as ug
...
mark_safe('<div style="text-align:center"><a href="/calendar/" target="_blank" onclick="return open_popup(this); return false">%s</a></div>' % ug(u'show full calendar'))
不幸的是,当我运行运行django-admin.py makemessages -l pl时,它在.po文件中不包含此字符串。我必须手动编辑它,写这行,然后它工作正常(字符串被翻译)。每次我运行makemessages都会发生这种情况。
答案 0 :(得分:1)
导入它并改为使用下划线:
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as ug
_('this is seen')
ug('this is not')
答案 1 :(得分:1)
我认为问题在于mark_safe和ug:
from django.utils.translation import ugettext as ug
...
mark_safe('<div style="text-align:center"><a href="/calendar/" target="_blank" onclick="return open_popup(this); return false">%s</a></div>' % ug(u'show full calendar'))
应该是:
from django.utils.translation import ugettext as ug
...
mark_safe('<div style="text-align:center"><a href="/calendar/" target="_blank" onclick="return open_popup(this); return false">%s</a></div>') % ug(u'show full calendar')
注意括号。