-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Lead: @cdriniIssues overseen by Drini (Staff: Team Lead & Solr, Library Explorer, i18n) [managed]Issues overseen by Drini (Staff: Team Lead & Solr, Library Explorer, i18n) [managed]Priority: 3Issues that we can consider at our leisure. [managed]Issues that we can consider at our leisure. [managed]Theme: InternationalizationMaking OpenLibrary work for both foreign-language users and books. [managed]Making OpenLibrary work for both foreign-language users and books. [managed]Type: Feature RequestIssue describes a feature or enhancement we'd like to implement. [managed]Issue describes a feature or enhancement we'd like to implement. [managed]
Description
With Open Library becoming increasingly more language-aware (edition aware carousals, etc), it would be nice if the "Random Book" feature was as well. For example, only showing books with French editions available when the user has chosen to display the website in French.
Relevant code
This function will need to take into account the current user language:
openlibrary/openlibrary/plugins/openlibrary/home.py
Lines 126 to 131 in 35e1ece
| class random_book(delegate.page): | |
| path = "/random" | |
| def GET(self): | |
| keys = get_random_borrowable_ebook_keys(1000) | |
| raise web.seeother(random.choice(keys)) |
openlibrary/openlibrary/plugins/openlibrary/home.py
Lines 112 to 123 in 35e1ece
| @cache.memoize( | |
| engine="memcache", key="home.random_book", expires=dateutil.HALF_HOUR_SECS | |
| ) | |
| def get_random_borrowable_ebook_keys(count: int) -> list[str]: | |
| solr = search.get_solr() | |
| docs = solr.select( | |
| 'type:edition AND ebook_access:[borrowable TO *]', | |
| fields=['key'], | |
| rows=count, | |
| sort=f'random_{random.random()} desc', | |
| )['docs'] | |
| return [doc['key'] for doc in docs] |
But only for populated languages. Something similar to this:
openlibrary/openlibrary/macros/QueryCarousel.html
Lines 17 to 23 in 10ed6be
| $ fallback_query = None | |
| $if user_lang_only: | |
| $ web_lang = get_lang() or 'en' | |
| $ user_lang= convert_iso_to_marc(web_lang) | |
| $if user_lang and user_lang in get_populated_languages(): | |
| $ fallback_query = query | |
| $ query = query + ' language:' + user_lang |
Metadata
Metadata
Assignees
Labels
Lead: @cdriniIssues overseen by Drini (Staff: Team Lead & Solr, Library Explorer, i18n) [managed]Issues overseen by Drini (Staff: Team Lead & Solr, Library Explorer, i18n) [managed]Priority: 3Issues that we can consider at our leisure. [managed]Issues that we can consider at our leisure. [managed]Theme: InternationalizationMaking OpenLibrary work for both foreign-language users and books. [managed]Making OpenLibrary work for both foreign-language users and books. [managed]Type: Feature RequestIssue describes a feature or enhancement we'd like to implement. [managed]Issue describes a feature or enhancement we'd like to implement. [managed]