简体   繁体   English

Django无法为djangojs制作消息

[英]Django cannot makemessages for djangojs

Currently I have this problem when trying to translate javascript files for Django. 目前我在尝试翻译Django的javascript文件时遇到此问题。 I have the url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'), in urls.py and get that one in the template. 我在urls.py中有url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),并在模板中获取该文件。 This does not seem to be the issue to translating, when I run the django-admin.py makemessages command, it will throw some errors and I do not know why. 这似乎不是翻译的问题,当我运行django-admin.py makemessages命令时,它会抛出一些错误,我不知道为什么。

   $ django-admin.py makemessages -d djangojs -l nl_NL --keep-pot
    CommandError: errors happened while running msguniq
    /Users/../../src/locale/djangojs.pot:120: context separator <EOT> within string
    /Users/../../src/locale/djangojs.pot:121: context separator <EOT> within string
    msguniq: found 2 fatal errors

This is what I find in the djangojs.pot file 这是我在djangojs.pot文件中找到的

#: static/jsi18n/djangojs.js:38 static/jsi18n/djangojs.js:46
#: static/jsi18n/nl/djangojs.js:84 static/jsi18n/nl/djangojs.js:92
msgid " "
msgid_plural ""
msgstr[0] ""
msgstr[1] ""

When I delete these lines with empty string and run the command again, it will simply add them again after the command ran. 当我用空字符串删除这些行并再次运行命令时,它将在命令运行后再次添加它们。 Anyone had this issue before? 以前有人有过这个问题吗?

I fixed this by removing the \\x04 strings from the djangojs.js file, and leave an empty string there. 我通过从djangojs.js文件中删除\\x04字符串来修复此问题,并在那里留下一个空字符串。 This is not a nice fix, but it seems to work for me. 这不是一个很好的解决方案,但它似乎对我有用。 I read some about this issue in this ticket https://code.djangoproject.com/ticket/17008 . 我在这张票https://code.djangoproject.com/ticket/17008上读到了一些关于这个问题的内容。 It seems like it cannot escape this in the javascript file. 似乎它无法在javascript文件中逃避这一点。

./static/jsi18n/djangojs.js:90: warning: Empty msgid.  It is reserved by GNU gettext:
                                         gettext("") returns the header entry with
                                         meta information, not the empty string.

This is the warning I get, but then again this seems to fix the translation problem for now. 这是我得到的警告,但是现在这似乎解决了翻译问题。

Error Description 错误说明

What happens here that it has created djangojs.js files like static/js/i18n/nl_NL/djangojs.js for all of your supported languages and in each language file it has '\\x04' strings inside these files 这里是什么情况,它创造了djangojs.js静态/ JS /国际化/ nl_NL / djangojs.js文件为所有支持的语言和在每个语言文件有“\\ X04”这些文件中的字符串

So when you run this command 所以当你运行这个命令

django-admin.py makemessages -d djangojs -l nl_NL

It considers these ** djangojs.js** files as a valid source code which is used to fetch strings of these for i18n, so it consider these '\\x04' string and create a msgid for it in .po files and create this entry in .pot file 它将这些** djangojs.js **文件视为有效的源代码,用于为i18n获取这些文件的字符串,因此它考虑这些'\\ x04'字符串并在.po文件中为它创建一个msgid并创建此条目在.pot文件中

msgid "^D"
msgstr ""

^D is an <EOT> character and that's what django says in the following error ^ D是一个<EOT>字符,这就是django在以下错误中所说的内容

djangojs.pot:120: context separator <EOT> within string

So where ever this error comes to your command exits here without completion. 所以这个错误来自你的命令退出这里没有完成。 After fixing it you need to re-run this command to execute it completely. 修复后,您需要重新运行此命令才能完全执行它。

Solution

You need to do these following things 你需要做以下事情

  1. No need to change any of your djangojs.js files 无需更改任何djangojs.js文件
  2. don't consider djangojs.js files for i18n 不要考虑i18n的djangojs.js文件

So in order to fix this you need to ignore these files and don't consider these files for i18n (internationalization) by adding --ignore keyword in makemessages command like below 因此,为了解决这个问题,您需要忽略这些文件,并且不要将这些文件视为i18n(国际化),方法是在makemessages命令中添加--ignore关键字,如下所示

django-admin makemessages --locale=$bn --domain=djangojs --ignore=static/js/i18n/*

It will fix your error. 它会修复你的错误。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM