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

Conversation

ChinoUkaegbu
Copy link
Contributor

Fixes bugs introduced in #9868

Technical

Testing

Screenshot

Screenshot (384)

Stakeholders

@cdrini

ChinoUkaegbu and others added 3 commits September 24, 2024 22:57
This allows us to enable localization when displaying the language
If not supported, displays English (en)
@@ -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'
Copy link
Collaborator

@cdrini cdrini Sep 24, 2024

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.

Suggested change
$ 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 :)

@cdrini cdrini self-assigned this Sep 24, 2024
Copy link
Collaborator

@cdrini cdrini left a 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
@ChinoUkaegbu
Copy link
Contributor Author

All done!

Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdrini cdrini merged commit 1aae0db into internetarchive:master Sep 24, 2024
3 checks passed
@cdrini cdrini added the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Sep 24, 2024
DanielleInkster pushed a commit to DanielleInkster/openlibrary that referenced this pull request Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants