Django 1.2.3 - 国际化 - makemessages不检测所有的字符串 [英] Django 1.2.3 - Internationalization - makemessages does not detect all strings

查看:141
本文介绍了Django 1.2.3 - 国际化 - makemessages不检测所有的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Django提供了一个简单易用的javascript库,它被用来像gettext一样在javascript文件中对字符串进行国际化。 / p>

我设置成功(至少内插函数有效),我可以为法语生成po文件。但是,并不是所有的字符串都被检测到。我真的不知道为什么,因为他们都是一样的。我在Django Trac和官方文档中找不到任何东西。



JavaScript代码位于模板中包含的外部文件中,Django显然找到它,因为它放在po文件中的两个字符串。



包含在HTML模板中:

 < script src ={{MEDIA_URL | default:'/ media /'}} js / list.jstype =text / javascript>< / script> 

JavaScript代码:

  / * --------------- 
*上传进度
* -------------- - * /
$(document).ready(function(){
$(function(){
$('#upload_form')。uploadProgress({
//。

/ *函数在开始上传之前调用* /
start:function(){
$(#upload_form)。hide();
文件名= $(#id_file)。val()。split(/ [\ / \\] /)pop();
fmts = gettext('上传%(filename) .. $)
dat = {
filename:filename
};
s = interpolate(fmts,dat,true);
$(#progress_filename .html($)
$(#progress_container)。show();
},

/ *函数调用每个时间栏更新* /
上传:功能(上传){
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('上传%(filename)s:%(percents)s%...');
dat = {
filename:filename,
percents:upload.percents
};
s = interpolate(fmts,dat,true);
$(#progress_filename)。html(s);
}
},

// ...

});
});
});


/ * --------------------
*确认对话框
* ---- ---------------- * /
函数delVid(title){
fmts = gettext('你真的要删除视频%(标题)的')?;
dat = {
title:title
};
s = interpolate(fmts,dat,true);
返回确认
}

函数abortVid(title){
fmts = gettext('你真的想中止视频的处理% (标题)S')?;
dat = {
title:title
};
s = interpolate(fmts,dat,true);
返回确认
}

第一部分是标准使用的JQuery的jquery.uploadprogress模块​​,第二部分只是确认弹出窗口的两个功能。



检测到的字符串都在第一部分:




  • '上传%(filename)s ...'

  • '保存%(filename)s ...'



我使用了命令django-admin.py -d djangojs -l fr,它生成了一个djangojs.po文件两串。我翻译了他们不幸的是,它们在运行时没有被翻译。看来我终于有两个问题。



任何想法?

解决方案

p> Django的Javascript消息解析非常脆弱。我已撰写详细信息为什么会这样。我还有一个修复Django 1.3附加到 Django ticket 7704 。 Django可能不接受补丁,也许你可以帮助他们解释他们为什么要这样做? :)


One more question about Django concerning localization of javascript files.

Django provides a small and convenient javascript library which is used like gettext to internationalize strings in javascript files.

I set it up successfully (at least the interpolate function works) and I could generate the po file for the French language. However, not all strings are detected. I don't really know why because they all look the same. I couldn't find anything on the Django Trac and the official docs.

The javascript code is in an external file included in the template and Django apparently found it because it put two strings in the po file.

The inclusion in the HTML template :

<script src="{{MEDIA_URL|default:'/media/'}}js/list.js" type="text/javascript"></script>

The javascript code :

/* ---------------
 * 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)
}

The first part is a standard use of the jquery.uploadprogress module for JQuery and the second part is just two functions for confirmation popups.

The detected strings are both in the first part :

  • 'Uploading %(filename)s...'
  • 'Saving %(filename)s...'

I used the command "django-admin.py -d djangojs -l fr" and it generated a djangojs.po file with these two strings. I translated them. Unfortunately, they are not translated at runtime. It seems that I have two problems finally.

Any idea ?

解决方案

Django's Javascript message parsing is quite fragile. I've written up the details why this is so. I also have a fix for Django 1.3 attached to Django ticket 7704. Django may not accept the patch, maybe you can help explain to them why they should? :)

这篇关于Django 1.2.3 - 国际化 - makemessages不检测所有的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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