[英]How to translate strings in javascript written in script tags of html in django?
嗨,我正在翻譯一個匈牙利語網站,我遇到了警報問題,並確認了我模板中的字符串。 我正在使用gettext('')
但這些字符串沒有出現在 po 文件中
我的網址.py
urlpatterns = patterns('',
url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
我通過運行 makemessages 創建了 po 文件 django.po,它在模板中標記為 trans 的所有字符串以及來自*.py
文件的字符串。 然后我運行了以下命令
django-admin.py makemessages -d djangojs -l hu_HU
它正在創建djangojs.po
。
此文件中出現的字符串均來自我的靜態文件夾中的 *.js 文件。
但是我如何在警報中使用我的字符串並確認寫在我的模板中。
這是我模板中的片段。
<script>
if($('#id_action').val()=='DEL'){
if(confirm(gettext('Are you sure you want to delete selected author(s) ?'))){
flag_action=true;
}
}
</script>
在我的模板中,我也有類似的東西,它也沒有出現在 po 文件中。
<li>
<a onclick="if(confirm(gettext('Are you sure you want to delete the selected author?'))){filter_content({{auth.id}},'DEL');return false;}" href="javascript:void(0)">
{% trans 'Delete' %}
</a>
</li>
gettext 中的字符串未出現在任何 po 中。
我在我的模板中包含了以下內容
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
用這個
var alert_var = {% blocktrans %}"Are you sure you want to delete selected author(s) ?" {% endblocktrans %};
<!-- begin snippet: js hide: false console: true babel: false -->
然后在任何需要的地方使用這個變量
正如 Arhot 所說{% blocktrans %}"Text..."{% endblocktrans %}
完美運行。
如果您在 html 文件中的<script>
標簽中使用它,單詞 ids 將在文件.po
生成,對應於 html traslations 而不是 javascript traslations。 我的意思是你會在文件django.po
而不是在djangojs.po
找到新詞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.