diff --git a/openlibrary/plugins/openlibrary/code.py b/openlibrary/plugins/openlibrary/code.py index a8d1e72ae33..98307adec8d 100644 --- a/openlibrary/plugins/openlibrary/code.py +++ b/openlibrary/plugins/openlibrary/code.py @@ -18,6 +18,7 @@ from openlibrary.core.batch_imports import ( batch_import, ) +from openlibrary.i18n import gettext as _ # make sure infogami.config.features is set if not hasattr(infogami.config, 'features'): @@ -1252,21 +1253,22 @@ def setup_template_globals(): get_cover_url, ) - SUPPORTED_LANGUAGES = { - "cs": {"localized": 'Czech', "native": "Čeština"}, - "de": {"localized": 'German', "native": "Deutsch"}, - "en": {"localized": 'English', "native": "English"}, - "es": {"localized": 'Spanish', "native": "Español"}, - "fr": {"localized": 'French', "native": "Français"}, - "hr": {"localized": 'Croatian', "native": "Hrvatski"}, - "it": {"localized": 'Italian', "native": "Italiano"}, - "pt": {"localized": 'Portuguese', "native": "Português"}, - "hi": {"localized": 'Hindi', "native": "हिंदी"}, - "sc": {"localized": 'Sardinian', "native": "Sardu"}, - "te": {"localized": 'Telugu', "native": "తెలుగు"}, - "uk": {"localized": 'Ukrainian', "native": "Українська"}, - "zh": {"localized": 'Chinese', "native": "中文"}, - } + def get_supported_languages(): + return { + "cs": {"code": "cs", "localized": _('Czech'), "native": "Čeština"}, + "de": {"code": "de", "localized": _('German'), "native": "Deutsch"}, + "en": {"code": "en", "localized": _('English'), "native": "English"}, + "es": {"code": "es", "localized": _('Spanish'), "native": "Español"}, + "fr": {"code": "fr", "localized": _('French'), "native": "Français"}, + "hr": {"code": "hr", "localized": _('Croatian'), "native": "Hrvatski"}, + "it": {"code": "it", "localized": _('Italian'), "native": "Italiano"}, + "pt": {"code": "pt", "localized": _('Portuguese'), "native": "Português"}, + "hi": {"code": "hi", "localized": _('Hindi'), "native": "हिंदी"}, + "sc": {"code": "sc", "localized": _('Sardinian'), "native": "Sardu"}, + "te": {"code": "te", "localized": _('Telugu'), "native": "తెలుగు"}, + "uk": {"code": "uk", "localized": _('Ukrainian'), "native": "Українська"}, + "zh": {"code": "zh", "localized": _('Chinese'), "native": "中文"}, + } web.template.Template.globals.update( { @@ -1283,7 +1285,7 @@ def setup_template_globals(): 'random': random.Random(), 'choose_random_from': random.choice, 'get_lang': lambda: web.ctx.lang, - 'supported_langs': SUPPORTED_LANGUAGES, + 'get_supported_languages': get_supported_languages, 'ceil': math.ceil, 'get_best_edition': get_best_edition, 'get_book_provider': get_book_provider, diff --git a/openlibrary/templates/site/alert.html b/openlibrary/templates/site/alert.html index 3415a40e4f7..2448ab724c9 100644 --- a/openlibrary/templates/site/alert.html +++ b/openlibrary/templates/site/alert.html @@ -1,6 +1,10 @@ $if not is_bot(): $:get_donation_include() +$ lang = get_lang() or 'en' +$ supported_languages = get_supported_languages() +$ active_ui_lang = supported_languages.get(lang) or supported_languages.get('en') +