readthedocs / readthedocs.org

The source code that powers readthedocs.org
https://readthedocs.org/
MIT License
7.95k stars 3.58k forks source link

Switching languages on non-default branch goes to default branch #4490

Open modelmat opened 5 years ago

modelmat commented 5 years ago

Details

When switching the language from en to ja here it goes to the default branch here (which since it has no ja language goes back to en.

Expected Result

It stays on the same branch/version you were previously on

Actual Result

Switches to the default branch,

stsewd commented 5 years ago

It makes sense to me to stay on the same branch. We'll need to send the current branch to the footer API, I think we already have this information.

humitos commented 5 years ago

Just adding more context here to have the URLs hardcoded:

At https://discordpy.readthedocs.io/en/rewrite/faq.html (rewrite version) the ja link from the version menu points to https://discordpy.readthedocs.io/ja/latest/faq.html (latest version) and it should points to https://discordpy.readthedocs.io/ja/rewrite/faq.html (rewrite version --same as we were when clicking the link)

stsewd commented 5 years ago

We can add the version in https://github.com/rtfd/readthedocs.org/blob/4911600c230809bd6fb3585d1903121db2928ad6/readthedocs/restapi/templates/restapi/footer.html#L21-L30

But, that is a function, we need to use this tag

https://github.com/rtfd/readthedocs.org/blob/4911600c230809bd6fb3585d1903121db2928ad6/readthedocs/core/templatetags/core_tags.py#L39-L43

But, we need to be careful with the performance when the project has a lot of versions.

And I think we already have some bugs related to the path that we should fix first (#4638)

humitos commented 5 years ago

The problem of linking to the specific version translated is that most of the docs do not have all the versions translated. So, in the end, we will be generating a lot of 404 for many projects also. I assume that's why we link to the "default version" instead.

We could add more logic here and "link to the same version only if that version exists in the translated project or fallback to the default version if not" but that won't work in the cases also, because the version may exists but the file does not.

stsewd commented 5 years ago

We already jump between files when switching versions, even if the file gives 404.

humitos commented 5 years ago

That's my point. It's not a good UX clicking on a link and get 404.