Opened 8 years ago

Closed 7 years ago

Last modified 16 months ago

#5846 closed Uncategorized (fixed)

locale.py fails if LANG is UTF-8

Reported by: Patrick Lauber <patrick.lauber@…> Owned by: nobody
Component: Internationalization Version: master
Severity: Normal Keywords:
Cc: lulihummel@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

on OSX Leopard with macports, mysql and postgresql LANG is defined as: UTF-8 ... on Tiger it was empty
This somehow breaks django:

Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/locale.py" in getdefaultlocale

  1. return _parse_localename(localename)

File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/locale.py" in _parse_localename

  1. raise ValueError, 'unknown locale: %s' % localename

ValueError at /admin/contact/company/
unknown locale: UTF-8

Change History (12)

comment:1 Changed 8 years ago by Patrick Lauber <patrick.lauber@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

ok the new terminal app on leopard exports the LANG variable. it can be disabled but i think a lot of people that will use Leopard will have the same problem because it is set as default.

comment:2 Changed 8 years ago by mtredinnick

  • Component changed from Uncategorized to Internationalization
  • Triage Stage changed from Unreviewed to Accepted

This is really a bug in Leopard. UTF-8 doesn't look like a valid value for the LANG environment variable. It should be something of the form language[_territory][.codeset], where UTF-8 is only the codeset part.

As you can see from the traceback, it isn't Django that's having the problem here. It's Python's standard locale library.

We can probably put a workaround into Django, but you should also file a bug with Apple, please, so that they fix this. It's just dumb.

comment:3 Changed 8 years ago by mtredinnick

Further feedback in this django-users thread and, particularly, here and here (found by Karen Tracy), suggest it's a Leopard bug.

I'll try to work out a robust way to ignore the problem in Django and not crash, but that's all we can do. We can't fix bad settings, so users will have to configure their machines by using the workarounds in the above links.

comment:4 Changed 8 years ago by Karen Tracey <kmtracey@…>

I claim one free pass, no expiration date, on leaving an 'l' out of Malcolm. :)

comment:5 Changed 8 years ago by anonymous

  • Cc lulihummel@… added; patrick.lauber@… removed

comment:6 Changed 7 years ago by Eduard Grebe <eduardgrebe@…>

I can confirm that the easiest workaround is to uncheck "Set LANG environment variable on sturtup" on the "advanced" tab in Terminal's preferences.

comment:7 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [7184]) Fixed #5846 -- Bullet-proofed the default timezone encoding test.

comment:8 follow-up: Changed 6 years ago by vitali.gribov@…

I'm also Mac OS X Leopard user and I have same problem.

# locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

# python -c 'import locale; print(locale.getdefaultlocale());'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/locale.py", line 441, in getdefaultlocale
    return _parse_localename(localename)
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/locale.py", line 373, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

When I simply exported variable LANG:

# export LANG=ru_RU.UTF
# locale
LANG="ru_RU.UTF-8"
LC_COLLATE="ru_RU.UTF-8"
LC_CTYPE="UTF-8"
LC_MESSAGES="ru_RU.UTF-8"
LC_MONETARY="ru_RU.UTF-8"
LC_NUMERIC="ru_RU.UTF-8"
LC_TIME="ru_RU.UTF-8"
LC_ALL=

I had same error again.

But when I did export for LC_CTYPE:

# export LC_CTYPE=ru_RU.UTF-8
# locale
LANG="ru_RU.UTF-8"
LC_COLLATE="ru_RU.UTF-8"
LC_CTYPE="ru_RU.UTF-8"
LC_MESSAGES="ru_RU.UTF-8"
LC_MONETARY="ru_RU.UTF-8"
LC_NUMERIC="ru_RU.UTF-8"
LC_TIME="ru_RU.UTF-8"
LC_ALL=
# python -c 'import locale; print(locale.getdefaultlocale());'
('ru_RU', 'UTF8')

It is because the sequence of environment variables check in python: LC_ALL, LC_CTYPE, LANG, LANGUAGE.

Note for Mac users:

# export LC_CTYPE=ru_RU.UTF-8
# locale
LANG=
LC_COLLATE="C"
LC_CTYPE="ru_RU.UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

comment:9 in reply to: ↑ 8 Changed 6 years ago by vitali.gribov@…

Sorry, I did mistake...

# export LANG=ru_RU.UTF-8

comment:10 Changed 3 years ago by anonymous

  • Easy pickings unset
  • Severity set to Normal
  • Type set to Uncategorized
  • UI/UX unset

comment:11 Changed 3 years ago by anonymous

Should be LANG=ru_RU.UTF-8 without inverted comma's not LANG="ru_RU.UTF-8" otherwise will not work

comment:12 Changed 16 months ago by us.ryokousha@…

This problem occurs due to an error with Mac OS X terminal and can be resolved in the the Terminal's preferences>advanced settings tab by unchecking "set locale environment variables on startup". This solution was found Here.

Note: See TracTickets for help on using tickets.
Back to Top