I am just before finishing line and feel that i don't finish yet! I created and compiled all of the messages in order to have a site with 2 languages and i received this error when running the server: AttributeError: module 'locale' has no attribute 'normalize'.
Can someone please help me?
Traceback (most recent call last):
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 306, in execute
parser = CommandParser(None, usage="%(prog)s subcommand [options] [args]", add_help=False)
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/base.py", line 47, in __init__
super().__init__(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/argparse.py", line 1633, in __init__
self._positionals = add_group(_('positional arguments'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 606, in gettext
return dgettext(_current_domain, message)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 570, in dgettext
codeset=_localecodesets.get(domain))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 505, in translation
mofiles = find(domain, localedir, languages, all=True)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 477, in find
for nelang in _expand_lang(lang):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 206, in _expand_lang
loc = locale.normalize(loc)
AttributeError: module 'locale' has no attribute 'normalize'
Process finished with exit code 1
This is how my locale folder looks like:
This is the function from gettext.py refered to the error. Seems the first line has the error:
def _expand_lang(loc):
loc = locale.normalize(loc)
COMPONENT_CODESET = 1 << 0
COMPONENT_TERRITORY = 1 << 1
COMPONENT_MODIFIER = 1 << 2
# split up the locale into its base components
mask = 0
pos = loc.find('@')
if pos >= 0:
modifier = loc[pos:]
loc = loc[:pos]
mask |= COMPONENT_MODIFIER
else:
modifier = ''
pos = loc.find('.')
if pos >= 0:
codeset = loc[pos:]
loc = loc[:pos]
mask |= COMPONENT_CODESET
else:
codeset = ''
pos = loc.find('_')
if pos >= 0:
territory = loc[pos:]
loc = loc[:pos]
mask |= COMPONENT_TERRITORY
else:
territory = ''
language = loc
ret = []
for i in range(mask+1):
if not (i & ~mask): # if all components for this combo exist ...
val = language
if i & COMPONENT_TERRITORY: val += territory
if i & COMPONENT_CODESET: val += codeset
if i & COMPONENT_MODIFIER: val += modifier
ret.append(val)
ret.reverse()
return ret
Later Edit: I've deleted the init files and now i got this error:
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 12, in <module>
from django.core.management.base import (
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/base.py", line 7, in <module>
from argparse import ArgumentParser
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/argparse.py", line 93, in <module>
from gettext import gettext as _, ngettext
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 409
advance to next entry in the seek tables
^
SyntaxError: invalid syntax
Process finished with exit code 1
I had the same. In PyCharm I had made a directory "locale" (with a __init__.py
for no reason whatsoever) for my internationalisation and got this message:
AttributeError: module 'locale' has no attribute 'normalize'
This is due to the fact it is looking for a Python module "locale" but that is masked by your Django directory "locale".
Either remove the __init__.py
and/or rename your directory "locale". I did both... "To stitch something twice is to stich it well" as we say in Holland.
It seems that everywhere on the net people use "locale" as directory for their internationlization. Hmm.. it now seems to me a bit like making a class with the name "Class" or a SQL table with the name "Table". I have seen in done, at times it works, I would never recommend it though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With