Skip to content

Commit

Permalink
fix: add localized current language to topbar (internetarchive#9906)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinoUkaegbu authored Sep 24, 2024
1 parent 59f061b commit 1aae0db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
34 changes: 18 additions & 16 deletions openlibrary/plugins/openlibrary/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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(
{
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion openlibrary/templates/site/alert.html
Original file line number Diff line number Diff line change
@@ -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')

<div id="topNotice">
<div class="page-banner page-banner-black page-banner-center">
<div class="iaBar">
Expand All @@ -9,7 +13,7 @@
<div class="language-component header-dropdown">
<details>
<summary>
<span>$(supported_langs[get_lang() or 'en']['native']) ($(get_lang() or 'en'))</span>
<span>$active_ui_lang['localized'] ($active_ui_lang['code'])</span>
<img class="translate-icon" src="/static/images/language-icon.svg" title="$_('Change Website Language')" alt="$_('Change Website Language')"/>
</summary>
<div class="language-dropdown-component">
Expand Down

0 comments on commit 1aae0db

Please sign in to comment.