|
@ -13,19 +13,87 @@ from patacrep.latex.syntax import tex2plain, parse_song |
|
|
LOGGER = logging.getLogger(__name__) |
|
|
LOGGER = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
BABEL_LANGUAGES = OrderedDict(( |
|
|
BABEL_LANGUAGES = OrderedDict(( |
|
|
('fr', 'french'), |
|
|
('de_de', 'german'), |
|
|
('en', 'english'), |
|
|
('de_at', 'austrian'), |
|
|
('de', 'german'), |
|
|
('eo_uy', 'esperanto'), |
|
|
('es', 'spanish'), |
|
|
('en_us', 'english'), # USenglish, american |
|
|
('it', 'italian'), |
|
|
('en_gb', 'british'), # UKenglish |
|
|
('pt', 'portuguese'), |
|
|
('en_ca', 'canadian'), |
|
|
|
|
|
('en_au', 'australian'), |
|
|
|
|
|
('en_nz', 'newzealand'), |
|
|
|
|
|
('es_es', 'spanish'), |
|
|
|
|
|
('fr_fr', 'french'), # francais |
|
|
|
|
|
('fr_ca', 'canadien'), |
|
|
|
|
|
('it_it', 'italian'), |
|
|
|
|
|
('la_LA', 'latin'), |
|
|
|
|
|
('pt_pt', 'portuguese'), # portuges |
|
|
|
|
|
('pt_br', 'brazilian'), # brazil |
|
|
|
|
|
|
|
|
|
|
|
## Remaining Babel language codes |
|
|
|
|
|
# ('??_??', 'afrikaans'), |
|
|
|
|
|
# ('??_??', 'bahasa'), |
|
|
|
|
|
# ('??_??', 'indonesian'), |
|
|
|
|
|
# ('??_??', 'indon'), |
|
|
|
|
|
# ('??_??', 'bahasai'), |
|
|
|
|
|
# ('??_??', 'bahasam'), |
|
|
|
|
|
# ('??_??', 'malay'), |
|
|
|
|
|
# ('??_??', 'melayu'), |
|
|
|
|
|
# ('??_??', 'basque'), |
|
|
|
|
|
# ('??_??', 'breton'), |
|
|
|
|
|
# ('??_??', 'bulgarian'), |
|
|
|
|
|
# ('??_??', 'catalan'), |
|
|
|
|
|
# ('??_??', 'croatian'), |
|
|
|
|
|
# ('??_??', 'czech'), |
|
|
|
|
|
# ('??_??', 'danish'), |
|
|
|
|
|
# ('??_??', 'dutch'), |
|
|
|
|
|
# ('??_??', 'estonian'), |
|
|
|
|
|
# ('??_??', 'finnish'), |
|
|
|
|
|
# ('??_??', 'acadian'), |
|
|
|
|
|
# ('??_??', 'galician'), |
|
|
|
|
|
# ('??_??', 'germanb'), |
|
|
|
|
|
# ('??_??', 'ngerman'), |
|
|
|
|
|
# ('??_??', 'naustrian'), |
|
|
|
|
|
# ('??_??', 'greek'), |
|
|
|
|
|
# ('??_??', 'polutonikogreek'), |
|
|
|
|
|
# ('??_??', 'hebrew'), |
|
|
|
|
|
# ('??_??', 'icelandic'), |
|
|
|
|
|
# ('??_??', 'interlingua'), |
|
|
|
|
|
# ('??_??', 'irish'), |
|
|
|
|
|
# ('??_??', 'lowersorbian'), |
|
|
|
|
|
# ('??_??', 'samin'), |
|
|
|
|
|
# ('??_??', 'norsk'), |
|
|
|
|
|
# ('??_??', 'nynorsk'), |
|
|
|
|
|
# ('??_??', 'polish'), |
|
|
|
|
|
# ('??_??', 'romanian'), |
|
|
|
|
|
# ('??_??', 'russian'), |
|
|
|
|
|
# ('??_??', 'scottish'), |
|
|
|
|
|
# ('??_??', 'slovak'), |
|
|
|
|
|
# ('??_??', 'slovene'), |
|
|
|
|
|
# ('??_??', 'swedish'), |
|
|
|
|
|
# ('??_??', 'serbian'), |
|
|
|
|
|
# ('??_??', 'turkish'), |
|
|
|
|
|
# ('??_??', 'ukrainian'), |
|
|
|
|
|
# ('??_??', 'uppersorbian'), |
|
|
|
|
|
# ('??_??', 'welsh'), |
|
|
)) |
|
|
)) |
|
|
|
|
|
|
|
|
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: |
|
|
try: |
|
|
return BABEL_LANGUAGES[lang] |
|
|
# 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: |
|
|
except KeyError: |
|
|
available = ", ".join(BABEL_LANGUAGES.keys()) |
|
|
available = ", ".join(BABEL_LANGUAGES.keys()) |
|
|
LOGGER.error('Unknown lang code: ' + lang + '. Supported: ' + available) |
|
|
LOGGER.error("Unknown language code '{}' (supported: {}). Using default 'english' instead.".format(lang, available)) |
|
|
return 'english' |
|
|
return 'english' |
|
|