Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add localized current language to topbar #9906

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading