Fix: Sort language autocomplete results alphabetically with prefix ma…#11929
Merged
RayBB merged 2 commits intointernetarchive:masterfrom Feb 26, 2026
Merged
Conversation
for more information, see https://pre-commit.ci
RayBB
approved these changes
Feb 26, 2026
Collaborator
RayBB
left a comment
There was a problem hiding this comment.
Thanks for the contribution! The change itself is solid and works well.
However, please avoid opening pull requests for issues that have already been offered to another contributor. In the future, wait until you are formally assigned the issue or have confirmed it is still available. This helps us avoid overlapping work and ensures a fair process for everyone.
Since this was a simple fix, we’ll move forward with it this time, but please follow this protocol for your next contribution.
RayBB
pushed a commit
that referenced
this pull request
Feb 26, 2026
Fix: Sort language autocomplete results alphabetically with prefix ma…
Contributor
Author
|
@RayBB Thank you for the feedback and my apologies for overlooking that. I will ensure I remember to wait to be assigned next time onwards. |
bhardwajparth51
pushed a commit
to bhardwajparth51/openlibrary
that referenced
this pull request
Mar 3, 2026
…tocomplete-sort Fix: Sort language autocomplete results alphabetically with prefix ma…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10765
The autocomplete_languages function in utils.py was yielding results in the order they were iterated from get_languages() rather than in a meaningful order. This PR collects all matches into a list first, then sorts them so that names starting with the search prefix rank above names that merely contain it elsewhere, with alphabetical ordering within each group.
Note: locale-aware collation (for correctly sorting translated language names for non-English users) is a known limitation. Implementing it safely in a concurrent web server would require a thread-safe i18n library like babel, which is not currently a dependency. This could be addressed as a separate issue. The docstring has also been updated to reflect the new correct output order.
Technical
Testing
frandarto confirm consistent behaviour.Screenshot
Not applicable, no UI changes to the autocomplete dropdown itself. JSON output before and after is documented in the linked issue.
Stakeholders
@RayBB