Browse Source

Exeption was never raised

pull/136/head
Louis 9 years ago
parent
commit
b2b80ef172
  1. 49
      patacrep/latex/__init__.py

49
patacrep/latex/__init__.py

@ -79,31 +79,30 @@ BABEL_LANGUAGES = OrderedDict((
def lang2babel(lang): def lang2babel(lang):
"""Return the language used by babel, corresponding to the language code""" """Return the language used by babel, corresponding to the language code"""
try: # Exact match
# Exact match if lang.lower() in BABEL_LANGUAGES:
if lang.lower() in BABEL_LANGUAGES: return BABEL_LANGUAGES[lang.lower()]
return BABEL_LANGUAGES[lang.lower()] # Only language code is provided (e.g. 'fr')
# Only language code is provided (e.g. 'fr') for babel in BABEL_LANGUAGES:
for babel in BABEL_LANGUAGES: if babel.startswith(lang.lower()):
if babel.startswith(lang.lower()): return BABEL_LANGUAGES[babel]
return BABEL_LANGUAGES[babel] # A non existent country code is provided (e.g. 'fr_CD').
# A non existent country code is provided (e.g. 'fr_CD'). language = lang.lower().split("_")[0]
language = lang.lower().split("_")[0] for babel in BABEL_LANGUAGES:
for babel in BABEL_LANGUAGES: if babel.startswith(language):
if babel.startswith(language): LOGGER.error(
LOGGER.error( "Unknown country code '{}'. Using default '{}' instead.".format(
"Unknown country code '{}'. Using default '{}' instead.".format( lang,
lang, babel
babel
)
) )
return BABEL_LANGUAGES[babel]
except KeyError:
available = ", ".join(BABEL_LANGUAGES.keys())
LOGGER.error(
"Unknown language code '{}' (supported: {}). Using default 'english' instead.".format(
lang,
available
) )
return BABEL_LANGUAGES[babel]
# Error: no (exact or approximate) match found
available = ", ".join(BABEL_LANGUAGES.keys())
LOGGER.error(
"Unknown language code '{}' (supported: {}). Using default 'english' instead.".format(
lang,
available
) )
return 'english' )
return 'english'

Loading…
Cancel
Save