Django

django-admin.py makemessages -l zh_TW

不知是否 Python 3.3 + Django 1.5.2 在 windows 上的 bug, 執行時一直出現錯誤訊息:

processing language zh_TW
Exception in thread Thread-29:
Traceback (most recent call last):
  File "C:\Python33\lib\threading.py", line 639, in _bootstrap_inner
    self.run()
  File "C:\Python33\lib\threading.py", line 596, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python33\lib\subprocess.py", line 1171, in _readerthread
    buffer.append(fh.read())
UnicodeDecodeError: 'cp950' codec can't decode byte 0x95 in position 725: illega
l multibyte sequence
IndexError: list index out of range

後來是把 C:\Python33\Lib\site-packages\django\core\management\commands\makemessages.py 第 95 行:

with open(django_po, 'rU') as fp:

改成

with open(django_po, 'rU', encoding='utf8') as fp:

才 OK 了. 因為根據 Django 的文件, PO 檔案格式必須是 utf8.