Skip to content
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

Addons: don't return current translation and include source language in projects.translations field #11292

Open
humitos opened this issue Apr 18, 2024 · 2 comments · May be fixed by #11361
Open
Assignees
Labels
Accepted Accepted issue on our roadmap Bug A bug

Comments

@humitos
Copy link
Member

humitos commented Apr 18, 2024

Currently, project.translations is returning all the translations from main_project. I realized that we don't always want this. This is only useful when browsing the source language of the documentation. However, when reading any of its translations project.translations should not show the current translation (the one the user is reading) and should show the source language as translation as well.

Example

If the project has English (source language), Spanish and Japanese translations, projects.translations should contain:

  • Spanish and Japanese, when hitting the English translation
  • English and Japanese, when hitting the Spanish translation

How to reproduce it

  1. Go to https://cpython-previews.readthedocs.io/es/latest/
  2. Open the flyout
  3. You will see that es is duplicated
    Screenshot_2024-04-18_13-28-04
@humitos humitos added Bug A bug Accepted Accepted issue on our roadmap labels Apr 18, 2024
@humitos humitos self-assigned this Apr 18, 2024
@humitos
Copy link
Member Author

humitos commented Apr 18, 2024

I think something like this could work:

diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py
index 4b598e21b..780e09091 100644
--- a/readthedocs/proxito/views/hosting.py
+++ b/readthedocs/proxito/views/hosting.py
@@ -342,7 +342,12 @@ class AddonsResponse:
                 )
 
         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).order_by("language")
+
+        # 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)
 
         data = {
             "api_version": "1",

@humitos
Copy link
Member Author

humitos commented Apr 18, 2024

I tested the previous diff locally and it works fine 👍🏼 . I need to open a PR and write some tests.

humitos added a commit that referenced this issue May 28, 2024
Return "source language project" in `projects.translations` when accessing a
translation of the "source language project".

Closes #11292
@humitos humitos linked a pull request May 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Bug A bug
Projects
Status: Needs review
Development

Successfully merging a pull request may close this issue.

1 participant