Using directory locale with __init__.py

78 views
Skip to first unread message

אורי

unread,
Sep 2, 2020, 12:04:47 PM9/2/20
to Django developers (Contributions to Django itself)
Django developers,

I had an exception because of using a directory locale with __init__.py, but I followed Django, which also uses a directory locale with __init__.py. It seems that there is a module locale in Python that can't be used with a local directory locale.



Do you think it's a good idea to use a directory locale with __init__.py?

This is the error message I received:

$ python tests_manage.py test
Traceback (most recent call last):
  File "tests_manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "E:\Uri\Speedy_Net\Git\speedy-net-public\.venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "E:\Uri\Speedy_Net\Git\speedy-net-public\.venv\lib\site-packages\django\core\management\__init__.py", line 334, in execute
    parser = CommandParser(usage='%(prog)s subcommand [options] [args]', add_help=False, allow_abbrev=False)
  File "E:\Uri\Speedy_Net\Git\speedy-net-public\.venv\lib\site-packages\django\core\management\base.py", line 50, in __init__
    super().__init__(**kwargs)
  File "C:\Program Files\Python36\lib\argparse.py", line 1637, in __init__
    self._positionals = add_group(_('positional arguments'))
  File "C:\Program Files\Python36\lib\gettext.py", line 612, in gettext
    return dgettext(_current_domain, message)
  File "C:\Program Files\Python36\lib\gettext.py", line 575, in dgettext
    codeset=_localecodesets.get(domain))
  File "C:\Program Files\Python36\lib\gettext.py", line 510, in translation
    mofiles = find(domain, localedir, languages, all=True)
  File "C:\Program Files\Python36\lib\gettext.py", line 482, in find
    for nelang in _expand_lang(lang):
  File "C:\Program Files\Python36\lib\gettext.py", line 206, in _expand_lang
    loc = locale.normalize(loc)
AttributeError: module 'locale' has no attribute 'normalize'
(.venv)

Adam Johnson

unread,
Sep 2, 2020, 12:17:44 PM9/2/20
to django-d...@googlegroups.com
Do you think it's a good idea to use a directory locale with __init__.py?

No, because as you've found it masks the locale stdlib module.

I prefer placing my entire django project within one package, this would allow you to have the locale directory as a submodule:

myproject/
  core/
    models.py
  locale/
    __init__.py

...

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CABD5YeEimeugNrwFsi9mYZ0kaDRzs%2B0122dDq55G8WAnsbGK3A%40mail.gmail.com.


--
Adam
Reply all
Reply to author
Forward
0 new messages