Skip to content

Addons: update projects.translations API response #11361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down