我在 Heroku 上部署了我的 Django 应用程序,并添加了 https://github.com/piotras/heroku-buildpack-gettext.git
这个 ugettext 构建包和应用程序的某些部分是注释翻译的。在本地运行正常,我不知道问题出在哪里。
例如,菜单项 Classes Types 未翻译,但其他部分已翻译。
{% trans "类类型"%}
模板
{% load i18n %}
....
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans "Class Types" %}<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>
<a href="{% url 'class_type-list' %}">
<span class="glyphicon glyphicon-list" aria-hidden="true"></span> {% trans "All" %}</a>
</li>
<li>
<a href="{% url 'class_type-new' %}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> {% trans "New" %}</a>
</li>
</ul>
</li>
....
ar/LC_MESSAGES.po
#: templates/back_office/class_type_list.html:4
#: templates/back_office/menu.html:37
msgid "Class Types"
msgstr "انواع الحلقات"
zh/LC_MESSAGES.po
#: templates/back_office/class_type_list.html:4
#: templates/back_office/menu.html:37
msgid "Class Types"
msgstr "Class Types"
最佳答案
经过一些研究,我发现将编译后的消息文件 (*.mo) 提交到 Heroku 会更好,这样翻译就可以正常工作了。
关于python - Heroku 上的 Django 翻译无法完全正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43743234/