makemessages 命令导致 html.py 个文件和一个 UnicodeDecodeError

makemessages command results in html.py files and a UnicodeDecodeError

当我运行这个命令时:

django-admin makemessages -l ar

它给出了这个错误:

Traceback (most recent call last):
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\utils\encoding.py", line 65, in force_text
s = str(s, encoding, errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 3107: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python36-32\Scripts\django-admin.exe\__main__.py", line 9, in <module>
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site- packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site- packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\commands\makemessages.py", line 384, in handle
potfiles = self.build_potfiles()
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\commands\makemessages.py", line 426, in build_potfiles
self.process_files(file_list)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\commands\makemessages.py", line 522, in process_files
self.process_locale_dir(locale_dir, files)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\commands\makemessages.py", line 590, in process_locale_dir
msgs, errors, status = popen_wrapper(args)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\utils.py", line 23, in popen_wrapper
force_text(output, stdout_encoding, strings_only=True, errors='strict'),
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\utils\encoding.py", line 69, in force_text
raise DjangoUnicodeDecodeError(s, *e.args)
django.utils.encoding.DjangoUnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 3107: invalid continuation byte. You passed in 

除了错误之外,还为每个 html 个文件创建了 html.py 个文件。例如:对于 index.html,会在模板文件夹中用它创建一个 index.html.py。这些 html.py 文件仅包含 'X' 和 'B' 个字符以及一些要翻译的文本。

例如:

BBBBBBBB
BBBBB BBBBBBB
    XXXX XXXXXXXXXXXXXXXXXXXXX
        XXXX XXXXXXXXX XXXXX XXX
        XXXX XXXXXXXXXXXXXXXXXX
              XXXX XXXXXXXXXXXXX
                      XXXX XXXXXXXXXXXXXXXXXX XX
                          XXX XXXXXXXXXXXXXX gettext(u'Les appels à projet') XXXXX
                        XXXX XXXXXXXXXXXXXXXXXXXXXXXXXX
                            XXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
                                XXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX
                                XXXXXX XXXXXXXXXXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX
                                XXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX
                            XXXXX
                        XXXXXX
                      XXXXXX
                      XXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX
                        XXXX XXXXXXXXXXXXXXXXXXXXXXXXX
                          XXXXXX XXXXXXXXXXXX XXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX
                                XXXXXXX
                                    XXXX
                                        XXXX gettext(u'Appel à projet') XXXXX
                                        XXXX gettext(u'Date de lencement') XXXXX
                                        XXXX gettext(u'Date de clature') XXXXX
                                        XXXX gettext(u'Année budjitaire') XXXXX
                                        XXXX gettext(u"N° d'apppel à projet") XXXXX
                                        XXXX gettext(u"Etat d'appel") XXXXX
                                        XXXX XXXX gettext(u'Action') XXXXX XXX
                                    XXXXX
                                XXXXXXXX
                                XXXXXXX
                                BBB BBBBBB BB BBBBBBBBBBB
                                    XXXX
                                        XXXXXXXXX
                                        XXXXXXXXX
                                        XXXXXXXXX

我已经有一个 Ar 的 .po 文件,其中有一些要翻译的文本,我已经在 2 个月前创建了它,并且翻译得很完美。

但是当我运行makemessages命令添加新文本进行翻译时,出现了上面的错误。

有什么想法吗?

而不是:

gettext(u'Les appels à projet')

尝试:

gettext('Les appels à projet')

希望对您有所帮助。

我找到了解决方案,我只是忘记了一些基础知识 :p

问题出在模板名称中,我有两个模板文件名为 CritéreGlobale.htmlCritéreSpecifique.html 问题是文件名称中的字符 é,在我编辑命名为 CritereGlobale.htmlCritereSpecifique.html 问题已解决,不再有 .html.py 文件,命令 运行 完美。

希望能帮到别人

我对 .html.py 重复的文件有同样的问题。我最终也得到了重复的 .txt.py 文件,即使在我的静态文件夹中也是如此!并且解决方案与 utf-8 无关。

我的问题是我在 项目级别 目录中执行了 django-admin makemessages -l <locale>。命令 makemessagescompilemessages 必须在 app 目录中执行。

附带说明一下,在执行命令之前,请不要忘记先在应用程序中创建 locale 文件夹。还使用 locale name 字符串(格式为 ll_LL,下划线和大写字母代表国家/地区)和 not 语言代码(格式为 ll-ll,带破折号且无大写字母)

我希望这对其他人有所帮助,因为这是我在 Whosebug 中发现的与此问题相关的唯一问题。