locale 'C' prevents linux installation from completing

Bug #1315064 reported by Ian Stakenvicius on 2014-05-01
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

If LC_ALL=C or the system locale is set to 'C', then the following occurs on linux, as of calibre-1.33:

Setting up command-line completion...

____________________ WARNING ____________________
Setting up completion failed with error:
 Traceback (most recent call last):
   File "/var/tmp/portage/app-text/calibre-1.34/work/calibre/src/calibre/linux.py", line 546, in setup_completion
     from calibre.gui2.tweak_book.main import option_parser as tweak_op
   File "/var/tmp/portage/app-text/calibre-1.34/work/calibre/src/calibre/gui2/tweak_book/__init__.py", line 13, in <module>
     from calibre.spell.dictionary import Dictionaries, parse_lang_code
   File "/var/tmp/portage/app-text/calibre-1.34/work/calibre/src/calibre/spell/dictionary.py", line 104, in <module>
     ul = parse_lang_code(get_system_locale() or 'en-US')
   File "/var/tmp/portage/app-text/calibre-1.34/work/calibre/src/calibre/spell/dictionary.py", line 56, in parse_lang_code
     raise ValueError('Invalid language code: %r' % raw)
 ValueError: Invalid language code: 'C'

Tracing through the code, get_system_locale() returns 'C' as is expected; parse_lang_code() then calls canonicalize_lang(), which returns None since 'C' is not a value it recognizes, this in turn triggers the ValueError exception.

I have successfully bypassed this (with a fully-working calibre so far as I can tell) by skipping the rase of the ValueError when parse_lang_code() is passed 'C' , but I'm thinking that it would probably be more correct to either have get_system_locale() return nothing if the locale is 'C' (so long as this is fine for other uses of get_system_locale()) or use parse_lang_code('en-US') when get_system_locale() returns 'C'.

Fixed in branch master. The fix will be in the next release. calibre is usually released every Friday.

 status fixreleased

Changed in calibre:
status: New → Fix Released
Ian Stakenvicius (axs-h) wrote :

The following modifies get_system_locale() to return None if locale is 'C'.

Since this function is only used in two places, the first being the place that triggers the error above, and the second being within 'get_lang()', upon which a 'None' value sets the lang to 'en', I think this patch is probably sufficient to fix the issue.

Ian Stakenvicius (axs-h) wrote :

oops, sorry, missed the update it seems.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers