Django removes translation in po file, string in mark_safe

天涯浪子 提交于 2019-12-24 09:58: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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/7876010/django-removes-translation-in-po-file-string-in-mark-safe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!