-
-
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
add current language to topbar in alert.html #9868
Changes from all commits
65af8c8
9c657f4
168d9e3
706c4c9
66d6f47
8068516
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
<div class="language-component header-dropdown"> | ||
<details> | ||
<summary> | ||
<span>$(supported_langs[get_lang() or 'en']['native']) ($(get_lang() or 'en'))</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will error if the user language is not supported! Eg if
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh note this also means we'll have to change what's inside the brackets, otherwise for unsupported languages (eg Albanian which has language code |
||
<img class="translate-icon" src="/static/images/language-icon.svg" title="$_('Change Website Language')" alt="$_('Change Website Language')"/> | ||
</summary> | ||
<div class="language-dropdown-component"> | ||
|
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.
These will need to be wrapped with the
_
in order to be actually localized, e.g.:Otherwise they will always be in English.
This also means we can't have this be a constant global, or else the
_
will only read the user language once! So we'll want to make this into a function so that_
can get the user language per-request. E.g.And then make this function publicly accessible from the template.
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.
That makes sense! Initially when I tried to create the dictionary, it followed this format:
but I kept getting an error message and so I left the dictionary in the format it currently is without the underscore with the intent of using the underscore in whatever page it's imported into. In PR #9889 I actually use the localization
_
here and it works so I'm wondering if I should follow that format in this case or just have thatget_supported_languages()
dictionary with the localization embedded inThere 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.
Ah you will have to import the
_
in the python file to get access to it, withfrom openlibrary.i18n import gettext as _
! That should do the trick. Was that maybe the error you were getting?Unfortunately
_
only works with static text, since essentially what happens is before the code is run, the python and html is analyzed and all_("...")
are extracted and put into a separate file for our translators. This means that_
doesn't work with variables, only literal strings.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.
The import worked, thank you! I've addressed the concerns (hopefully) in #9906
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.
Wonderful thank you! I responded there 😊