Skip to content

Instantly share code, notes, and snippets.

@sh4dowb sh4dowb/

Last active Jun 19, 2020
What would you like to do?
python3 gettext ascii codec can't decode - even after headers - pygettext and msgfmt

getting this error while using gettext on python?

Traceback (most recent call last):
  File "/usr/lib/python3.8/", line 613, in translation
    t = _translations.setdefault(key, class_(fp))
  File "/usr/lib/python3.8/", line 261, in __init__
  File "/usr/lib/python3.8/", line 456, in _parse
    catalog[str(msg, charset)] = str(tmsg, charset)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 4: ordinal not in range(128)

keep this header pygettext generates, we need “Content-Type: text/plain; charset=UTF-8\n”:

msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2020-06-19 23:43+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: 1.5\n"

but it still doesn't work?
make sure your file ends with .po
I accidentally kept the extension as .pot and was getting that error
hope this helps somebody lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.