diff --git a/readthedocs/proxito/tests/test_hosting.py b/readthedocs/proxito/tests/test_hosting.py index 06d6abd35f3..09cafa8eee4 100644 --- a/readthedocs/proxito/tests/test_hosting.py +++ b/readthedocs/proxito/tests/test_hosting.py @@ -300,6 +300,7 @@ def test_flyout_translations(self): ) assert r.status_code == 200 + # Hitting the English version of the docs, will return Japanese as translation assert len(r.json()["projects"]["translations"]) == 1 assert r.json()["projects"]["translations"][0]["slug"] == "translation" assert r.json()["projects"]["translations"][0]["language"]["code"] == "ja" @@ -308,6 +309,28 @@ def test_flyout_translations(self): == "https://project.dev.readthedocs.io/ja/latest/" ) + # Hitting the Japanese version of the docs, will return English as translation + r = self.client.get( + reverse("proxito_readthedocs_docs_addons"), + { + "url": "https://project.dev.readthedocs.io/ja/latest/", + "client-version": "0.6.0", + "api-version": "1.0.0", + }, + secure=True, + headers={ + "host": "project.dev.readthedocs.io", + }, + ) + assert r.status_code == 200 + assert len(r.json()["projects"]["translations"]) == 1 + assert r.json()["projects"]["translations"][0]["slug"] == "project" + assert r.json()["projects"]["translations"][0]["language"]["code"] == "en" + assert ( + r.json()["projects"]["translations"][0]["urls"]["documentation"] + == "https://project.dev.readthedocs.io/en/latest/" + ) + def test_flyout_downloads(self): fixture.get( Version, diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index 55291009052..0e263951710 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -348,7 +348,15 @@ def _v1(self, project, version, build, filename, url, user): ) main_project = project.main_language_project or project - project_translations = main_project.translations.all().order_by("language") + + # Exclude the current project since we don't want to return itself as a translation + project_translations = main_project.translations.all().exclude( + slug=project.slug + ) + # Include main project as translation if the current project is one of the translations + if project != main_project: + project_translations |= Project.objects.filter(slug=main_project.slug) + project_translations = project_translations.order_by("language") data = { "api_version": "1",