Javascript文件中的Django翻译

时间:2018-09-24 04:45:19

标签: javascript django language-translation

我遵循了Django doc来内部化js文件,但是它不起作用。这是我的设置:

settings.py:

[HttpPost]  
publicActionResultUploadFile(HttpPostedFileBase file)  
{  
    try  
    {  
        if (file.ContentLength > 0)  
        {  
            string _FileName = Path.GetFileName(file.FileName);  
            string _path = Path.Combine(Server.MapPath("~/UploadedFiles"), _FileName);  
            file.SaveAs(_path);  
        }  
        ViewBag.Message = "File Uploaded Successfully!!";  
        return View();  
    }  
    catch  
    {  
        ViewBag.Message = "File upload failed!!";  
        return View();  
    }  
}  

根项目中的urls.py:

LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'),)

在文件夹中运行以下命令,并生成.po和.mo文件:

from django.views.i18n import JavaScriptCatalog
from django.conf.urls.i18n import i18n_patterns

urlpatterns += i18n_patterns(
    path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'),
)

django.po文件:

django-admin makemessages -l pt_BR

django-admin makemessages -d djangojs -l pt_BR

django-admin makemessages -a

django-admin compilemessages

在html模板中使用,如下所示:

msgid "Customer"
msgstr "Cliente"

什么也没有发生,文本继续用英语显示。有人知道这会是什么吗?

0 个答案:

没有答案