Skip to content

[LLM] Show related articles in translation view - #168

Merged
menny merged 2 commits into
mainfrom
feature/related-articles-41
Sep 7, 2026
Merged

menny merged 2 commits into
mainfrom
feature/related-articles-41

Conversation

@menny

@menny menny commented Sep 7, 2026

Copy link
Copy Markdown
Member

What

Adds a Related articles section below the target card in the translation view (source-language, inline, up to 8 items).

  • WikipediaApi.getRelatedArticles(): generator=search with gsrsearch=morelike:{title} + prop=pageprops|extracts (2-sentence intro extracts).
  • TranslationRepository.getRelatedArticles(): filters to main-namespace, valid, non-disambiguation pages; excludes the source article; caps at limit.
  • TranslateViewModel: new RelatedArticlesState (Hidden/Loading/Loaded) flow, fetched lazily after translation, cached per source article; tapping a related article translates it directly via fetchRelatedTranslation(). Empty/error hides silently.
  • UI: RelatedArticlesSection in TranslationView, wired through TranslateScreen; strings localized (en + ar, de, es, fr, he, ru).

Why

The legacy rest_v1/page/related endpoint is decommissioned (HTTP 403, phab:T376297). CirrusSearch morelike is WMF's canonical replacement and what Extension:RelatedArticles itself uses.

Verification

  • 10 new tests (4 repository, 5 ViewModel, 1 network MockWebServer parsing) — all green.
  • ./gradlew testDebugUnitTest + spotlessApply clean.
  • Manually verified on device (installGoogleDebug): search “office” → “Office” → Hebrew translation + related list below.

Closes #41

What: adds a Related articles section below the target card in the
translation view. Related concepts are fetched lazily after translation
via the stable Action API morelike query (generator=search with
pageprops|extracts), filtered to main-namespace non-disambiguation
pages, capped at 8, cached per source article. Tapping a related
article translates that concept directly. Section hides silently on
empty/error so translation is never disturbed. Strings localized to
all supported languages.

Why: the legacy rest_v1/page/related endpoint is decommissioned
(HTTP 403, phab:T376297); CirrusSearch morelike is WMF's canonical
replacement and matches what Extension:RelatedArticles uses. This
implements the source-language inline (Option A) design.

Made by Muse Spark.

Closes #41
@anysoftkeyboard-bot

anysoftkeyboard-bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

The changes are well-architected, resilient, and thoroughly tested. Coroutine cancellation, stale response discarding, and title normalization are all properly handled, and localizations are complete across all supported languages.

@anysoftkeyboard-bot anysoftkeyboard-bot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes requested due to an unhandled coroutine cancellation issue in TranslateViewModel that causes stale state overwrites, along with a parameter encoding issue in TranslationRepository.

…ze titles

What: tracks the in-flight related-articles fetch as a Job and cancels
it on new loads, searches, back-navigation, and clear; results and
errors are only posted when the translation view still shows the same
source article (sourceLang + pageid guard); CancellationException is
rethrown instead of swallowed. Multi-word titles are normalized to
MediaWiki canonical form (spaces to underscores) in the morelike query.

Why: fixes a race where a late related-articles response overwrote the
state of a newer translation, and hardens the CirrusSearch query for
multi-word titles.

Made by Muse Spark.

@anysoftkeyboard-bot anysoftkeyboard-bot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes are well-architected, resilient, and thoroughly tested, with complete localizations and proper handling of coroutine cancellation and stale responses.

@menny
menny merged commit 619adaa into main Sep 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show related articles in some way in the translation view

2 participants