Opened 17 years ago

Closed 17 years ago

Last modified 11 years 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: dev
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 by Patrick Lauber <patrick.lauber@…>, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

Component: UncategorizedInternationalization
Triage Stage: UnreviewedAccepted

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 by Malcolm Tredinnick, 17 years ago

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 by Karen Tracey <kmtracey@…>, 17 years ago

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

comment:5 by anonymous, 17 years ago

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

comment:6 by Eduard Grebe <eduardgrebe@…>, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

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

comment:8 by vitali.gribov@…, 16 years ago

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=

in reply to:  8 comment:9 by vitali.gribov@…, 16 years ago

Sorry, I did mistake...

# export LANG=ru_RU.UTF-8

comment:10 by anonymous, 12 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

comment:11 by anonymous, 12 years ago

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

comment:12 by us.ryokousha@…, 11 years ago

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