Same string with different translation

老子叫甜甜 提交于 2019-12-12 09:29:29

问题


I have one string that can be translated in varius part of my code in two different way.

Now if Use django-admin makemessages -l it

I get in django.po this:

#: pingapi/ping.py:17 pingapi/nots.py:10
msgid "may"
msgstr "maggio"

But I would want two different translation:

#: pingapi/ping.py:17 
msgid "may"
msgstr "posso"

#: pingapi/nots.py:10
msgid "may"
msgstr "maggio"

If I run django-admin compilemessage with the translation file posted up, I get:

Error: errors happened while running msgmerge
 error 'duplicate message definition' 

Any Hints? I'm using Django.


回答1:


You can use gettext's context for that. Django has added support for that in 1.3 release (in code) and 1.4 (for templates), see https://docs.djangoproject.com/en/dev/topics/i18n/translation/#contextual-markers

Update:

For example following code:

from django.utils.translation import pgettext, ugettext

month = pgettext("month name", "May")
month = pgettext("fifth month", "May")
month = ugettext("May")

Translates to:

#: foo/views.py:4
msgctxt "month name"
msgid "May"
msgstr ""

#: foo/views.py:5
msgctxt "fifth month"
msgid "May"
msgstr ""

#: foo/views.py:6
msgid "May"
msgstr ""

Each message being different and can be translated differently.



来源:https://stackoverflow.com/questions/10235822/same-string-with-different-translation

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