【发布时间】:2010-10-07 06:24:04
【问题描述】:
另一个关于 Django 的关于 javascript 文件本地化的问题。
Django 提供了一个小而方便的 javascript 库,它可以像 gettext 一样用于将 javascript 文件中的字符串国际化。
我设置成功(至少 interpolate 函数有效),我可以生成法语的 po 文件。但是,并非所有字符串都被检测到。我真的不知道为什么,因为它们看起来都一样。我在 Django Trac 和官方文档上找不到任何内容。
javascript 代码位于模板中包含的外部文件中,Django 显然找到了它,因为它在 po 文件中放置了两个字符串。
包含在 HTML 模板中:
<script src="{{MEDIA_URL|default:'/media/'}}js/list.js" type="text/javascript"></script>
javascript代码:
/* ---------------
* Upload progress
* --------------- */
$(document).ready(function() {
$(function() {
$('#upload_form').uploadProgress({
//...
/* function called just before starting the upload */
start: function() {
$("#upload_form").hide();
filename = $("#id_file").val().split(/[\/\\]/).pop();
fmts = gettext('Uploading %(filename)s...');
dat = {
filename: filename
};
s = interpolate(fmts,dat,true);
$("#progress_filename").html(s);
$("#progress_container").show();
},
/* function called each time bar is updated */
uploading: function(upload) {
if (upload.percents >= 100) {
window.clearTimeout(this.timer);
fmts = gettext("Saving %(filename)s...");
dat = {
filename: filename
};
s = interpolate(fmts,dat,true);
$("#progress_filename").html(s);
} else {
fmts = gettext('Uploading %(filename)s : %(percents)s%...');
dat = {
filename: filename,
percents: upload.percents
};
s = interpolate(fmts,dat,true);
$("#progress_filename").html(s);
}
},
//...
});
});
});
/* --------------------
* Confirmation dialogs
* -------------------- */
function delVid(title) {
fmts = gettext('Do you really want to delete the video "%(title)s"?');
dat = {
title: title
};
s = interpolate(fmts,dat,true);
return confirm(s)
}
function abortVid(title) {
fmts = gettext('Do you really want to abort the processing of the video "%(title)s"?');
dat = {
title: title
};
s = interpolate(fmts,dat,true);
return confirm(s)
}
第一部分是 JQuery 的 jquery.uploadprogress 模块的标准用法,第二部分只是确认弹出窗口的两个函数。
检测到的字符串都在第一部分:
- '正在上传 %(filename)s...'
- '正在保存 %(filename)s...'
我使用了命令“django-admin.py -d djangojs -l fr”,它使用这两个字符串生成了一个 djangojs.po 文件。我翻译了它们。不幸的是,它们在运行时没有被翻译。看来我终于有两个问题了。
有什么想法吗?
【问题讨论】:
标签: javascript python django internationalization gettext