相同的字符串与不同的翻译 [英] Same string with different translation

查看:131
本文介绍了相同的字符串与不同的翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在,如果使用django-admin makemessages -l它

,那么我可以用两种不同的方式将一个字符串翻译成我的代码。 >

我进入django.po这个:

 #:pingapi / ping。 py:17 pingapi / nots.py:10 
msgid可能
msgstrmaggio

但是我想要两个不同的翻译:

 #:pingapi / ping.py:17 
msgid可能
msgstrposso

#:pingapi / nots.py:10
msgid可以
msgstrmaggio

如果我运行django-admin compilemessage与翻译文件发布,我得到:

 错误:错误发生在运行msgmerge 
错误'重复消息定义'

任何提示?我正在使用Django。

解决方案

可以使用gettext的上下文。 Django已经在1.3版本(代码)和1.4(模板)中添加了该功能,请参阅 https://docs.djangoproject.com/en/dev/topics/i18n/translation/#contextual-markers



更新:



例如以下代码:

  from django.utils.translation import pgettext, ugettext 

month = pgettext(month name,May)
month = pgettext(第五个月,May)
month = ugettext(May )

转换为:

#:foo / views.py:4 
msgctxt月份名称
msgid可以
msgstr

# foo / views.py:5
msgctxt第五个月
msgid可以
msgstr

#:foo / views.py:6
msgidMay
msgstr

每个消息是不同的,可以翻译


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.

解决方案

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.

这篇关于相同的字符串与不同的翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆