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

[7786] Remove locale prefix from URLs #8096

Merged
merged 8 commits into from
Mar 27, 2024
Merged

Conversation

alexander-griffen
Copy link
Contributor

Relevant issue(s)

Fixes #7786

What does this do?

Removes the locale prefix from the URL, and instead uses the session value as the prioritised manner of setting the locale.

Why was this needed?

Reduce the number or URL permutations per request in order to reduce admin burden

Implementation notes

Screenshots

Notes to reviewer


Have you updated the changelog? If this is not necessary, put square brackets around this: skip changelog

@alexander-griffen alexander-griffen self-assigned this Jan 12, 2024
@alexander-griffen alexander-griffen force-pushed the 7786-remove-locale-prefix-urls branch 3 times, most recently from 3a338da to c34265b Compare January 12, 2024 16:25
@alexander-griffen alexander-griffen force-pushed the 7786-remove-locale-prefix-urls branch 3 times, most recently from e1812f8 to c0a6274 Compare February 26, 2024 14:58
@alexander-griffen alexander-griffen marked this pull request as ready for review February 26, 2024 16:35
@alexander-griffen alexander-griffen changed the title [7786] WIP Remove locale prefix from URLs [7786] Remove locale prefix from URLs Feb 26, 2024
@gbp gbp force-pushed the 7786-remove-locale-prefix-urls branch 3 times, most recently from c65c575 to 0534a8b Compare March 5, 2024 10:15
@gbp
Copy link
Member

gbp commented Mar 6, 2024

Transient spec failure, with rspec spec/controllers/general_controller_spec.rb:117 spec/integration/localisation_spec.rb:27 --seed=62743, fixed in #8152

alexander-griffen and others added 2 commits March 13, 2024 12:09
This uses CSS selectors rather than labels, so it will work with the
webpage being in other languages.

Also needed to prefix route in an integration test to get the correct
locale rendered, this is because the `signin_path` now doesn't specify
the locale so the session object hasn't been set.
This will be used to strip the locale from the current URL so we always
have clean URLs.
@gbp gbp force-pushed the 7786-remove-locale-prefix-urls branch from 0534a8b to ebd4cca Compare March 13, 2024 12:10
gbp added a commit to mysociety/whatdotheyknow-theme that referenced this pull request Mar 26, 2024
gbp and others added 6 commits March 27, 2024 11:57
When the locale changes we need to ensure the users session is updated.
Normally this would happen using the session object but we have a
middleware to strip "empty" sessions updates, this includes the locale
key. This appears to be left over from an optimisation for Varnish
cache. See [1] and [2].

Storing a different key makes the session update work. This is important
for this feature as we will be removing the prefixed locale in the URL
and we have to ensure this is set correctly.

[1] fe895b0
[2] https://chris.heald.me/2011/rails-varnish-cookie-sessions-and-csrf-tokens/
Update routing filter to never inject locale prefix, as well as updating
fixtures and test examples which have hard-coded URLs to no longer have
locale prefixes in them.

This also disabled some integration tests where we look for localised
content as these will need to be re-written once we handle locales
differently in upcoming commits.
This commit removes the RoutingFilter which injects the locale parameter
into the URL. It also removes any references to this in test setup.
This is now unused without the locale routing filter. The default locale
has to now come after the session locale when selection which locale to
use.
When processing requests for URLs where the locale is a prefix, we now:
1. Redirect to the same URL with the locale as a parameter, this is done
   via routing redirects.

2. Set the locale in the session. This is done in the existing
   `set_gettext_locale` before action callback.

3. Finally, we redirect to the same URL without the locale at all as
   this information is retrieved from the session or cookies.

The redirect is skipped for the `PublicBodyController#show` action as
there is already redirection in place there to redirect to localised
version of the `PublicBody#url_name`.
@gbp gbp force-pushed the 7786-remove-locale-prefix-urls branch from 0ee6a01 to 11cbe40 Compare March 27, 2024 11:57
@gbp gbp merged commit f78788d into develop Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove locale prefix from URLs and make session-based
2 participants