comparison babel/core.py @ 536:9facabfe91d0

catch exception if environment contains an invalid locale setting (fixes #200)
author fschwarz
date Fri, 11 Mar 2011 16:20:57 +0000
parents e93f68837913
children 632b2338e6dd
comparison
equal deleted inserted replaced
535:bfda66d78688 536:9facabfe91d0
657 locale = locale.split(':')[0] 657 locale = locale.split(':')[0]
658 if locale in ('C', 'POSIX'): 658 if locale in ('C', 'POSIX'):
659 locale = 'en_US_POSIX' 659 locale = 'en_US_POSIX'
660 elif aliases and locale in aliases: 660 elif aliases and locale in aliases:
661 locale = aliases[locale] 661 locale = aliases[locale]
662 return '_'.join(filter(None, parse_locale(locale))) 662 try:
663 return '_'.join(filter(None, parse_locale(locale)))
664 except ValueError:
665 pass
663 666
664 def negotiate_locale(preferred, available, sep='_', aliases=LOCALE_ALIASES): 667 def negotiate_locale(preferred, available, sep='_', aliases=LOCALE_ALIASES):
665 """Find the best match between available and requested locale strings. 668 """Find the best match between available and requested locale strings.
666 669
667 >>> negotiate_locale(['de_DE', 'en_US'], ['de_DE', 'de_AT']) 670 >>> negotiate_locale(['de_DE', 'en_US'], ['de_DE', 'de_AT'])
Copyright (C) 2012-2017 Edgewall Software