本文介绍了“django-admin.py makemessages”中的错误还是xgettext调用? - > “警告:未终止的字符串”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

django-admin.py makemessages 在包装真长字符串的情况下会出现错误warning:unterminated string:

django-admin.py makemessages dies with errors "warning: unterminated string" on cases where really long strings are wrapped:

string = "some text \
          more text\
          and even more"

这些字符串甚至不需要翻译 - 例如sql查询字符串。
当我连接字符串时,问题消失了,但结果看起来很丑,需要时间才能加入...

These strings don't even need to be translated - e.g. sql query strings.The problem goes away when I concatenate the string, but the result looks ugly and it takes time to join them...

有没有人有问题这个?你有没有找到一种解决方法?

Does anyone have a problem like this? Have you found a way to fix it?

我有以下版本的工具:

xgettext -0.17,gettext-0.17,django-1.0.2,python-2.6.2

xgettext-0.17, gettext-0.17, django-1.0.2, python-2.6.2

有一个在这个问题上,但它被关闭可能是因为错误只出现在组件版本的某些组合。

There was a ticket on this issue, but it was closed probably because the error appears only in some combination of component versions.

编辑:发现问题的根源 - xgettext向sterr打印警告消息,django将其作为致命错误并退出。

found the source of problem - xgettext prints warning messages to sterr and django takes them as fatal errors and quits.

xgettext调用是0 - 成功。我猜,django应该认识到它是成功的,而不是因为警告而退出。

return status of xgettext call is 0 - "success". I guess that django should recognize it as success and not quit because of warnings.

有趣的是,如果需要翻译,xgettext仍然会提取反斜杠包装的字符串,但会发出警告stderr(unterminated string)和.po文件(国际化消息不应包含`\r'转义序列

Interestinly xgettext still extracts backslash-wrapped strings if they need to be translated, but gives warnings in stderr ("unterminated string") and .po file ("internationalized messages should not contain the `\r' escape sequence")

xgettext调用如下:

xgettext call is the following:

xgettext -d django -L Python --keyword=gettext_noop \
         --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 \
         --keyword=ugettext_noop --keyword=ugettext_lazy \
         --keyword=ungettext_lazy:1,2
         --from-code UTF-8 -o - source_file.py

从django调用/core/management/commands/makemessages.py

called from django/core/management/commands/makemessages.py

推荐答案

我可以想到两种可能性:你可能会有更多的空间行尾的反斜线;或者您可能会以某种方式结束您的源代码中的错误的行尾字符(例如,当您的Python期待Unix样式时,Windows风格,从而禁用反斜杠)。

I can think of two possibilities: you might have an extra space after your backslash at the end of the line; or you might be somehow ending up with the wrong line-ending characters in your source (e.g. Windows-style when your Python is expecting Unix-style, thus disabling the backslashes).

无论如何,我将利用C风格的自动字符串连接:

Either way, I would take advantage of C-style automatic string concatenation:

>>> string = ("some text "
...           "more text "
...           "and even more")
>>> string
'some text more text and even more'

或者,如果你不使用多行字符串:

Alternatively, if you don't mind newlines ending up in there, use multi-line strings:

>>> string = """some text
...             more text
...             and even more"""

IMO这些看起来更好,在重构时更不脆弱。

IMO these look much nicer, and are much less fragile when refactoring.

这是否有帮助?

这篇关于“django-admin.py makemessages”中的错误还是xgettext调用? - > “警告:未终止的字符串”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 03:44