I keep ending up with an empty catalog in my jsi18n JavaScript. I have tried all the solutions on StackOverflow including Empty catalog when internationalizing JavaScript code, but the catalog is still empty.

我一直在jsi18n JavaScript中找到一个空目录。在国际化JavaScript代码时,我已经尝试了StackOverflow上的所有解决方案,包括空目录,但目录仍为空。

My setup is this:

我的设置是这样的:

project_dir
- locale
  - nl (contains LC_MESSAGES with django.po and djangojs.po)
- app1
- app2
- main_app
  - settings.py
  - urls.py
  - wsgi.py

In settings.py I have

在settings.py我有

# Where to find locale
LOCALE_PATHS = (
    os.path.join(SITE_ROOT, 'locale'),
)

SITE_ROOT is the absolute path to my project dir, so this translates to

SITE_ROOT是我的项目目录的绝对路径,因此转换为

In urls.py I have

在urls.py我有

# i18n
js_info_dict = {
    'domain': 'djangojs',
    'packages': ('wrnpro', ),
}

and

    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

as part of my urls.

作为我的网址的一部分。

If I run the app and call http://localhost:8000/jsi18n/ I get

如果我运行应用程序并调用http:// localhost:8000 / jsi18n /我得到

/* gettext library */
var catalog = new Array();
function pluralidx(count) { return (count == 1) ? 0 : 1; }
… 

So far I have tried every variation of settings etc. I could find, but the catalog remains empty.

到目前为止,我已经尝试了各种设置等变化我可以找到,但目录仍然是空的。

When running make messages and compile messages my JavaScript get text strings are found and translated. The django.po and .mo files are in the locale directory.

当运行make消息并编译消息时,我的JavaScript获取文本字符串被找到并翻译。 django.po和.mo文件位于语言环境目录中。

Anyone?

任何人?

3 个解决方案

#1


5

This is what ended up working for me:

这最终为我工作:

js_info_dict = {
   'domain': 'django',
   'packages': None,
}

urlpatterns = [
    url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
    # ...
]

Still not working? Troubleshooting tips:

I don't know particularly why this works, but I can tell you how I found out how to make it work. If you use the same troubleshooting technique, maybe you'll find a way too. I used Python debugger, like this:

我不知道为什么会这样,但我可以告诉你我是如何找到它的方法。如果您使用相同的故障排除技术,也许您也会找到一种方法。我使用Python调试器,像这样:

def javascript_catalog_pdb(*args, **kwargs):
    import pdb
    pdb.set_trace()
    return javascript_catalog(*args, **kwargs)

url_patterns = [
    url(r'^jsi18n/$', javascript_catalog_pdb, js_info_dict, name='javascript-catalog'),
    ...
]

Then using PDB, I stepped into javascript_catalog, until I got to the line:

然后使用PDB,我进入javascript_catalog,直到我到达该行:

catalog, plural = get_javascript_catalog(locale, domain, packages)

I then experimented with different values for domain and packages, right there in the debugger, until I discovered the values I needed.

然后,我在调试器中尝试了域和包的不同值,直到我发现了我需要的值。

更多相关文章

  1. 【问题解决方案】ImportError: No module named 'pygal'
  2. Python 黏包及黏包解决方案
  3. 解决Linux下运行Python脚本显示“: 没有那个文件或目录”的问题
  4. win8.1 cygwin - pip正在安装到windows python目录中吗?
  5. py2exe使用相对路径的当前目录问题
  6. 无法安装ndg-httpsclient或者我的解决方案错误
  7. Shell脚本更改带变量的目录
  8. Python编程系列教程第16讲——拷贝自身到系统目录
  9. linux系统更改目录和文件的权限总结

随机推荐

  1. Android 屏幕滑动事件
  2. android setAudioSource failed
  3. android ndk native_activity.h
  4. Android的NDK开发(5)————Android JNI
  5. Android(安卓)studio编译警告:请使用 -Xli
  6. Android版本检测\自动更新 (转的别人的)
  7. Android 长按识别图中二维码
  8. android 自学笔记
  9. Android属性动画设置中心点
  10. Android Initialization Process ---- An