国际化JavaScript代码时的空目录 [英] Empty catalog when internationalizing JavaScript code

查看:111
本文介绍了国际化JavaScript代码时的空目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置我的Django应用程序中JavaScript代码的国际化



我的Django应用程序有一个区域设置子目录,正确生成 djangojs.po 文件。包定义如下:

 #urls.py 
js_info_dict = {
'packages': ('my_project',),
}

./管理.py makemessages 的功能很好,因为 .po 文件包含所有要翻译的字符串,但没有JavaScript字符串在网站上被翻译,目录总是空的。

解决方案

我也有一些问题。这是它对我有用的:



将其添加到yr root urls.py:

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


urlpatterns = ',

#enable在javascript中使用翻译字符串
#source:https://docs.djangoproject.com/en/dev/topics/i18n/translation/#module-django.views .i18n
(r'^ jsi18n / $','django.views.i18n.javascript_catalog',js_info_dict),


pre>

在JS文件中使用:

  var somevar = gettext '文本翻译'); 

编译django翻译文件:在从项目根运行的shell / ,设置等):

  #fornormal django files(.py,.html):
django-admin.py makemessages --locale = de
#for javascript文件。来源:http://stackoverflow.com/a/3571954/268125
django-admin.py makemessages -a -d djangojs --locale = de
#将翻译文件编译为机器代码
django-admin.py compilemessages --locale = de


I'm trying to set up Internationalization of JavaScript code in my Django application.

My Django app has a locale subdirectory with a properly generated djangojs.po file. The package definition is as follows:

# urls.py
js_info_dict = {
    'packages': ('my_project',),
} 

./manage.py makemessages worked well as the .po file contains all the to-be-translated strings but no JavaScript string ever gets translated on the website and the catalog is always empty.

解决方案

I also had some problems with. This is how it works for me:

Add this to yr root urls.py:

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


urlpatterns = patterns('',                   

    #enable using translation strings in javascript
    #source: https://docs.djangoproject.com/en/dev/topics/i18n/translation/#module-django.views.i18n
    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

)

In JS files use:

var somevar = gettext('Text to translate');

To compile django translation files: In a shell/terminal run from the project root (where 'apps', 'settings', etc lie):

#for "normal django files" (.py, .html):
django-admin.py makemessages --locale=de
#for javascript files. source: http://stackoverflow.com/a/3571954/268125
django-admin.py makemessages -a -d djangojs --locale=de
#to compile the translation files to machine code
django-admin.py compilemessages --locale=de

这篇关于国际化JavaScript代码时的空目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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