-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix: add localized current language to topbar #9906
Conversation
This allows us to enable localization when displaying the language
If not supported, displays English (en)
for more information, see https://pre-commit.ci
@@ -1,6 +1,9 @@ | |||
$if not is_bot(): | |||
$:get_donation_include() | |||
|
|||
$ lang = get_lang() or 'en' | |||
$ use_lang = lang if lang in get_supported_languages() else 'en' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this should do the trick! This will (1) avoid calling gets_supported_languages() twice which is a small perf boost, and (2) make it a little clearer since we'll only have one notion of "active ui language" floating around.
$ use_lang = lang if lang in get_supported_languages() else 'en' | |
$ supported_languages = get_supported_languages() | |
$ active_ui_lang = supported_languages.get(lang) or supported_languages.get('en') |
Then you can do:
<span>$active_ui_lang['localized'] ($active_ui_lang['code'])</span>
This will require duplicating the code
also inside the dictionary, but I think that's a worthwhile change! It makes all the data needed for rendering containing in the returned dictionary :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small fix! Everything else looks great 😊
We fetch the dictionary once to improve performance and use the code key to ensure consistency
All done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, thank you @ChinoUkaegbu !
Tested:
- https://testing.openlibrary.org/status?lang=sq
- https://testing.openlibrary.org/status?lang=en
- https://testing.openlibrary.org/status?lang=fr
And all behaved correctly
Fixes bugs introduced in #9868
Technical
Testing
Screenshot
Stakeholders
@cdrini