Django javascript翻译gettext总是显示翻译的字符串

时间:2016-01-25 16:12:33

标签: django translation gettext

django gettext翻译总是显示翻译的短语(英语),而不是我在html(荷兰语)中的原始短语。

{% trans "" %}的正常翻译效果很好。只有javascript才会出现此问题。

我没有/locale/nl/,因为我的默认字符串已经是荷兰语。

我已将翻译设置为文档(在settings,urls.py和html中)以及Javascript文件中的gettext('string')http://localhost:8081/jsi18n/中的Django目录显示了原始的荷兰语字符串:

django.catalog = {
"<p>De sluitdatum is verlopen op ": "<p>The closing date has passed on ", 
"<p>De vragenlijst is ": "<p>The questionnaire is ", 
"<p>U bent nog niet geaccepteerd voor deze vragenlijst.</p><p>U ontvangt een uitnodiging per email wanneer u bent geaccepteerd!</p>": "<p>You are not yet accepted for this survey.</p><p>You will receive an invitation by email when you are accepted!</p>", 
"<p>U heeft de vragenlijst voltooid!</p> <p><small>U kunt uw antwoorden nog aanpassen tot de vragenlijst is gesloten.</small></p>": "<p>You have completed the questionnaire!</p> <p><small>You can change your answers until the survey close date</small></p>", 
"Er zijn dubbele emailaddressen gevonden: ": "There are duplicate emailaddresses", 
"Volgende": "Next", 
"Vorige": "Previous"
};

但这些句子永远不会以荷兰语显示出来。

1 个答案:

答案 0 :(得分:0)

我认为您忘记在djangojs.po文件中添加翻译后的字符串(对于原始默认语言环境,在这种情况下为荷兰语。)

或者也许您应该在i18n_patterns()中添加javascript-catalog网址:

i18n_urlpatterns = i18n_patterns(
    url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
)
urlpatterns += i18n_urlpatterns

请注意,在这种情况下,Django返回2个不同的js文件: