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

Move the i18n/ url outside of the i18n_patterns function as per the Django documentation #10754

Merged
merged 10 commits into from
May 13, 2024

Conversation

jkemper-pca
Copy link
Contributor

@jkemper-pca jkemper-pca commented Apr 11, 2024

Putting the code path("i18n/", include("django.conf.urls.i18n")) within the i18n_patterns(*urlpatterns) causes issues when the app tries to switch languages. Setting up the urls this way is specifically warned against in the Django documentation.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Description of Change

The "i18n/" url has been moved outside of the i18n_patterns() function by removing it from the urls.py in arches file (because all urls there get passed to the i18n_patterns() function and is added instead in the project's urls.py file after the rest of the urls are passed to the function.

Issues Solved

When trying to switch languages using the top-right language switcher, the behaviour was inconsistent and often reloaded the page but did not switch the language.

One way that I've found this happens is:

  1. Two languages enabled (ex. "en"(default), "fr")
  2. Navigate to the search page
  3. Switch language to French using the drop-down in the top-right
  4. It should switch correctly
  5. Now try switching back to English
  6. It will reload the page but will stay in French

With this code change, the language will continue to swap correctly

Checklist

  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Ticket Background

Further comments

There might be other ways to changing the code around to take the i18n path out of the i18n_patterns so if this PR is just used to prompt looking into the issue that's fine with me.

If this change is merged, the documentation will also need to be updated slightly because the code in urls.py is used in a snippet on the Localizing Arches page

@jacobtylerwalls jacobtylerwalls self-assigned this May 8, 2024
@jacobtylerwalls jacobtylerwalls changed the base branch from master to dev/7.6.x May 13, 2024 14:46
Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks @jkemper-pca. Verified this fix works.

I retargeted your PR to dev/7.6.x, since master isn't a branch we use for development. (We should probably delete it.)

Since this is a change that requires user action (for existing projects), could you update 7.6.0.md and make these changes?

  • add a changelog
  • add an upgrade instruction (probably inserting a step after "In settings.py" so that it becomes "In urls.py")

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Great, thanks for the update!

@jacobtylerwalls jacobtylerwalls merged commit fc16daf into archesproject:dev/7.6.x May 13, 2024
6 checks passed
@chrabyrd chrabyrd mentioned this pull request May 22, 2024
6 tasks
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.

Language switcher doesn't work on projects using i18n_patterns
3 participants