Add query argument to filter by language support

This commit is contained in:
rubenwardy 2024-02-26 00:45:25 +00:00
parent 3e6d6864b3
commit 40d572d645
2 changed files with 8 additions and 1 deletions

@ -189,6 +189,7 @@ Supported query parameters:
* `tag`: Filter by tags.
* `flag`: Filter to show packages with [Content Flags](/help/content_flags/).
* `game`: Filter by [Game Support](/help/game_support/), ex: `Wuzzy/mineclone2`. (experimental, doesn't show items that support every game currently).
* `lang`: Filter by translation support, eg: `en`/`de`/`ja`/`zh_TW`.
* `random`: When present, enable random ordering and ignore `sort`.
* `limit`: Return at most `limit` packages.
* `hide`: Hide content based on [Content Flags](/help/content_flags/).

@ -52,7 +52,8 @@ class QueryBuilder:
ret = f"{self.search} - {ret}"
if self.game:
ret = gettext("%(package_type)s for %(game_name)s", package_type=ret, game_name=self.game.title)
meta = self.game.get_translated(load_desc=False)
ret = gettext("%(package_type)s for %(game_name)s", package_type=ret, game_name=meta["title"])
return ret
@ -132,6 +133,8 @@ class QueryBuilder:
if self.game:
self.game = Package.get_by_key(self.game)
self.has_lang = args.get("lang")
if cookies and request.cookies.get("hide_nonfree") == "1":
self.hide_nonfree = True
@ -197,6 +200,9 @@ class QueryBuilder:
if self.game:
query = query.filter(Package.supported_games.any(game=self.game, supports=True))
if self.has_lang:
query = query.filter(Package.translations.any(language_id=self.has_lang))
for tag in self.tags:
query = query.filter(Package.tags.any(Tag.id == tag.id))