Skip to content

Instantly share code, notes, and snippets.

@federicobond
Last active February 4, 2024 12:43
Show Gist options
  • Save federicobond/fd59c7b22b90795e26d2 to your computer and use it in GitHub Desktop.
Save federicobond/fd59c7b22b90795e26d2 to your computer and use it in GitHub Desktop.
Fix errors / warnings when running `python manage.py makemessages` with `xlwt` installed.
#!/bin/bash
#
# This scripts solves the following error when running Django's makemessages with xlwt installed.
# It also gets rid of the warnings.
#
# CommandError: errors happened while running xgettext on UnicodeUtils.py
# xgettext: ./env/lib/python2.7/site-packages/xlwt/UnicodeUtils.py:1: Unknown encoding "windows-1252". Proceeding with ASCII instead.
# xgettext: Non-ASCII string at ./env/lib/python2.7/site-packages/xlwt/UnicodeUtils.py:37.
# Please specify the source encoding through --from-code or through a comment
#  as specified in http://www.python.org/peps/pep-0263.html.
files_1252=(
./env/lib/python2.7/site-packages/xlwt/CompoundDoc.py
./env/lib/python2.7/site-packages/xlwt/UnicodeUtils.py
./env/lib/python2.7/site-packages/xlwt/Autofit.py
./env/lib/python2.7/site-packages/xlwt/Bitmap.py
./env/lib/python2.7/site-packages/xlwt/Cell.py
./env/lib/python2.7/site-packages/xlwt/Column.py
./env/lib/python2.7/site-packages/xlwt/ExcelFormula.py
./env/lib/python2.7/site-packages/xlwt/ExcelFormulaLexer.py
./env/lib/python2.7/site-packages/xlwt/Row.py
./env/lib/python2.7/site-packages/xlwt/Style.py
./env/lib/python2.7/site-packages/xlwt/Workbook.py
./env/lib/python2.7/site-packages/xlwt/Worksheet.py
./env/lib/python2.7/site-packages/xlwt/examples/country.py
)
files_1251=(
./env/lib/python2.7/site-packages/xlwt/Bitmap.py
./env/lib/python2.7/site-packages/xlwt/examples/blanks.py
./env/lib/python2.7/site-packages/xlwt/examples/col_width.py
./env/lib/python2.7/site-packages/xlwt/examples/country.py
./env/lib/python2.7/site-packages/xlwt/examples/dates.py
./env/lib/python2.7/site-packages/xlwt/examples/format.py
./env/lib/python2.7/site-packages/xlwt/examples/formula_names.py
./env/lib/python2.7/site-packages/xlwt/examples/formulas.py
./env/lib/python2.7/site-packages/xlwt/examples/hyperlinks.py
./env/lib/python2.7/site-packages/xlwt/examples/image.py
./env/lib/python2.7/site-packages/xlwt/examples/merged.py
./env/lib/python2.7/site-packages/xlwt/examples/merged0.py
./env/lib/python2.7/site-packages/xlwt/examples/merged1.py
./env/lib/python2.7/site-packages/xlwt/examples/mini.py
./env/lib/python2.7/site-packages/xlwt/examples/num_formats.py
./env/lib/python2.7/site-packages/xlwt/examples/numbers_demo.py
./env/lib/python2.7/site-packages/xlwt/examples/outline.py
./env/lib/python2.7/site-packages/xlwt/examples/panes.py
./env/lib/python2.7/site-packages/xlwt/examples/row_styles.py
./env/lib/python2.7/site-packages/xlwt/examples/row_styles_empty.py
./env/lib/python2.7/site-packages/xlwt/examples/sst.py
./env/lib/python2.7/site-packages/xlwt/examples/unicode1.py
./env/lib/python2.7/site-packages/xlwt/examples/unicode2.py
)
function convert() {
local encoding=$1
shift
local files=("$@")
for file in "${files[@]}"; do
iconv -f "$encoding" -t utf-8 "$file" > "$file.new"
mv -f "$file.new" "$file"
sed -i "" "s/coding: $encoding/coding: utf-8/" "$file"
done
}
convert 'windows-1251' "${files_1251[@]}"
convert 'windows-1252' "${files_1252[@]}"
@federicobond
Copy link
Author

In spanish:

xgettext: ./env/lib/python2.7/site-packages/xlwt/Autofit.py:1: Codificaci'on desconocida "windows-1252". Se proceder'a con ASCII en su lugar.
xgettext: ./env/lib/python2.7/site-packages/xlwt/Bitmap.py:1: Codificaci'on desconocida "windows-1251". Se proceder'a con ASCII en su lugar.
xgettext: ./env/lib/python2.7/site-packages/xlwt/Cell.py:1: Codificaci'on desconocida "windows-1252". Se proceder'a con ASCII en su lugar.
xgettext: ./env/lib/python2.7/site-packages/xlwt/Column.py:1: Codificaci'on desconocida "windows-1252". Se proceder'a con ASCII en su lugar.
xgettext: ./env/lib/python2.7/site-packages/xlwt/CompoundDoc.py:1: Codificaci'on desconocida "windows-1252". Se proceder'a con ASCII en su lugar.
xgettext: Cadena no ASCII en ./env/lib/python2.7/site-packages/xlwt/CompoundDoc.py:209.
          Especifique la codificaci'on del c'odigo fuente utilizando --from-code.

@danniehakan
Copy link

Hi! I'm having this issue running on python 3.5.2 and django 1.10.7 with xlwt installed via tablib via django-import-export.

Do you know why this is happening in the first place? I cannot find a reference to this issue in the library itself.

@i-salameh95
Copy link

How to run this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment