Skip to content

Proxito: redirect to default version from root language #10313

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 6 commits into from
May 24, 2023

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented May 10, 2023

Closes #2968

@stsewd stsewd requested a review from a team as a code owner May 10, 2023 02:03
@stsewd stsewd requested a review from humitos May 10, 2023 02:03
@stsewd stsewd requested a review from a team as a code owner May 10, 2023 02:11
@stsewd stsewd requested a review from benjaoming May 10, 2023 02:11
as set in your project settings.

This works for readthedocs.io (|org_brand|) and :doc:`custom domains </custom-domains>`.
For |com_brand| this can be enabled by contacting :doc:`support </support>`.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is since this "feature" is only available when using the new proxito implementation.

Copy link
Contributor

@benjaoming benjaoming left a comment

Choose a reason for hiding this comment

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

This looks great!! Happy to close an old issue so efficiently.

I wondered about cases where a project contains:

a) No translations
b) A file called /es/test.html
c) ..or maybe a file called /es/latest/test.html

But I concluded that we aren't raising the "TranslationNotFound" error unless the path also doesn't exist? Is that correct?

Comment on lines +421 to +422
"/en",
"/en/",
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@stsewd
Copy link
Member Author

stsewd commented May 11, 2023

But I concluded that we aren't raising the "TranslationNotFound" error unless the path also doesn't exist? Is that correct?

Not sure if I understand the question, but for the cases that you listed:

a) No translations: since the project doesn't have translations (just an en language), a TranslationNotFound error will be raised for a path like /es/latest/
b) A file called /es/test.html: If the project is a multiversion project and has the es translation, test.html will be interpreted as a version, and since the that version doesn't exist a version not found will be raised.
c) ..or maybe a file called /es/latest/test.html: If the project is a multiversion project and has the es translation, that will be resolved correctly.

Co-authored-by: Benjamin Balder Bach <[email protected]>
@benjaoming
Copy link
Contributor

benjaoming commented May 12, 2023

@stsewd

a) No translations: since the project doesn't have translations (just an en language), a TranslationNotFound error will be raised for a path like /es/latest/

If a project is a multiversion project, it cannot use paths like /es/file.html or /es/latest/file.html for regular files at all, because they will just return TranslationNotFound? Or can a project have a file stored in this path if it doesn't have an es translation?

I'm wondering if strictly always resolving [a-z]{2}/ as a language slug without a fallback to a file path is too strict. There are A LOT of language codes, for instance Norwegian is no and might be useful for other things if the project doesn't want a Norwegian translation :)

We can definitely treat this as a separate issue.

@stsewd
Copy link
Member Author

stsewd commented May 12, 2023

If a project is a multiversion project, it cannot use paths like /es/file.html or /es/latest/file.html for regular files at all, because they will just return TranslationNotFound? Or can a project have a file stored in this path if it doesn't have an es translation?

If a project is a multiversion project, it always needs to serve a file from a language subpath. If it's a single version project it can have any path in the url, it will resolve just fine.

@benjaoming
Copy link
Contributor

benjaoming commented May 12, 2023

Garh of course 🤦 I managed to ask a very silly question. I think where I got it wrong initially was thinking that we do redirects to a default language like how Django i18n url patterns does. Which we don't - we use our own /page redirects.

I don't have anymore inputs or questions :)

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Thanks for the whole work you have done on El Proxito lately. This PR is a lot easier to review now that we all have a better understanding of how things work.

Comment on lines 90 to 91
A link to the root language of your documentation (``<slug>.readthedocs.io/en/``)
will redirect to the :term:`default version` of that translation.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
A link to the root language of your documentation (``<slug>.readthedocs.io/en/``)
will redirect to the :term:`default version` of that translation.
A link to the root language of your documentation (``<slug>.readthedocs.io/<lang>/``)
will redirect to the :term:`default version` of that language.


Root language redirects on |com_brand| can be enabled by contacting :doc:`support </support>`.

For example::
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
For example::
For example, accessing the English language of the project will redirect you to the ``stable`` version::

"/en",
"/en/",
]
for path in paths:
Copy link
Member

Choose a reason for hiding this comment

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

Instead of a for here, shouldn't these be pytest.parametrize? (I know you love that one 😉 ). It would be clearer when the test fail to know what is the exact case we are testing.

Copy link
Member

Choose a reason for hiding this comment

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

Note there are more cases like this in the other tests we can change to pytest.parametrize.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think parametrize doesn't work with tests that inherit from TestCase, I'll give it a try

Copy link
Member Author

Choose a reason for hiding this comment

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

@stsewd stsewd merged commit c9884a0 into main May 24, 2023
@stsewd stsewd deleted the redirect-from-root-language branch May 24, 2023 15:54
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.

Redirect to the default version of any translation when visiting /{lang}/
3 participants