Django removes translation in po file, string in m

2019-08-06 11:45发布

I try to translate string, which is in mark_safe() function:

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'))

Unfortunately, when I run run django-admin.py makemessages -l pl, it doesn't include this string in .po file. I have to edit it manually, write this line and then it works fine (the string is translated). It happens each time I run makemessages.

2条回答
该账号已被封号
2楼-- · 2019-08-06 12:26

I think the problem was with mark_safe and 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'))

should be:

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')

Notice the brackets.

查看更多
神经病院院长
3楼-- · 2019-08-06 12:35

Import it and use as underscore instead:

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as ug
_('this is seen')
ug('this is not')
查看更多
登录 后发表回答