From b2b80ef172aaba152d42c19854c19c12a63561f8 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 29 Oct 2015 09:20:30 +0100 Subject: [PATCH] Exeption was never raised --- patacrep/latex/__init__.py | 49 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/patacrep/latex/__init__.py b/patacrep/latex/__init__.py index 78251f4e..d596abae 100644 --- a/patacrep/latex/__init__.py +++ b/patacrep/latex/__init__.py @@ -79,31 +79,30 @@ BABEL_LANGUAGES = OrderedDict(( def lang2babel(lang): """Return the language used by babel, corresponding to the language code""" - try: - # Exact match - if lang.lower() in BABEL_LANGUAGES: - return BABEL_LANGUAGES[lang.lower()] - # Only language code is provided (e.g. 'fr') - for babel in BABEL_LANGUAGES: - if babel.startswith(lang.lower()): - return BABEL_LANGUAGES[babel] - # A non existent country code is provided (e.g. 'fr_CD'). - language = lang.lower().split("_")[0] - for babel in BABEL_LANGUAGES: - if babel.startswith(language): - LOGGER.error( - "Unknown country code '{}'. Using default '{}' instead.".format( - lang, - babel - ) + # Exact match + if lang.lower() in BABEL_LANGUAGES: + return BABEL_LANGUAGES[lang.lower()] + # Only language code is provided (e.g. 'fr') + for babel in BABEL_LANGUAGES: + if babel.startswith(lang.lower()): + return BABEL_LANGUAGES[babel] + # A non existent country code is provided (e.g. 'fr_CD'). + language = lang.lower().split("_")[0] + for babel in BABEL_LANGUAGES: + if babel.startswith(language): + LOGGER.error( + "Unknown country code '{}'. Using default '{}' instead.".format( + lang, + 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'