Django makemessages不适用于JS文件 [英] Django makemessages not working for JS files

查看:133
本文介绍了Django makemessages不适用于JS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

settings.py

INSTALLED_APPS = (
    ...
    'myprojectname',
    ...
)

STATIC_ROOT = '/var/www/a_valid_path/'

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

urls.py

js_info_dict = {
    'domain': 'djangojs',
    'packages': ('myprojectname',),
}

urlpatterns = patterns('',
    ...
    url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
    ...
)

我的项目结构如下:

|- projectname
|--- app1
|--- app2
|--- manage.py
|- virtualenv
|- static
|--- js
|--- css

我也在我的项目的根文件夹中具有 locale 文件夹,其中 manag e.py 位于。

I also have the locale folder in the root folder of my project, where manage.py is located.

./manage.py -l ro -d djangojs



我的问题



它不工作。没有生成 .po 文件。服务器端的翻译工作,但是(视图+模板)。我遵循所有的建议,依然没有。甚至尝试自己创建 djangojs.po 文件,以查看Django是否删除它,或者执行某些操作 - 不需要。

My problem

It's not working. No .po file is being generated. Server-side translation works, however (views + templates). I've followed all advice, and still nothing. Even tried to create the djangojs.po file myself to see if Django deletes it, or does something with it -- nope.

没有错误被生成,只是处理区域设置ro 被显示(在很短的时间内 - 如果你问我太短),就是这样。任何帮助?

No error is generated, just processing locale ro is shown (for a really short time -- too short if you ask me), and that's that. Any help?

编辑:忘了提到我的文件夹包含JS文件不在每个Django应用程序内,而是在一个单独的位置。仍然,Django不应该看到 STATICFILES_DIRS

Forgot to mention that my folder containing the JS files is not inside each Django app, but in a separate location. Still, shouldn't Django look inside the STATICFILES_DIRS?

推荐答案

Django的邮件消息只会从您的 TEMPLATE_DIRS 之一的文件发出消息。所以你想翻译的任何文件都需要在这些目录之一中。

Django's makemessages only will make messages from files that are in on one of your TEMPLATE_DIRS. So any files you want to translate need to be in one of those directories.

你可以通过以下几种方法来实现:

You can do that in one several ways:


  • 将* .js文件放在您的 TEMPLATE_DIRS之一

  • 将你的JS列入html文件

  • 将需要翻译的所有字符串放在dom上的数据属性中,并通过JS从dom获取它们

这篇关于Django makemessages不适用于JS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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