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

Use Localize middleware in frontend user and nocache controllers #7892

Closed
wants to merge 3 commits into from

Conversation

jacksleight
Copy link
Contributor

@jacksleight jacksleight commented Apr 12, 2023

Fixes #7890
Fixes #7893

Only implements the Localize middlewear rather than the full statamic.web group. Could be done in the routes file but I just copied the approach from the FrontendController class.

@what-the-diff
Copy link

what-the-diff bot commented Apr 12, 2023

PR Summary

  • Added constructor to UserController class
    This update creates a new constructor in the UserController class, making it easier to manage user-related functionalities.

  • Extended BaseController with NoCache feature and Localize middleware
    The NoCache/Controller now inherits from BaseController and includes a constructor that utilizes the Localize middleware. This allows better control over caching and improved localization support.

@robdekort
Copy link
Contributor

Just pulled this in and it works like a charm. Thanks Jack!

@jacksleight jacksleight changed the title Use Localize middleware in frontend UserController Use Localize middleware in frontend user and nocache controllers Apr 12, 2023
@jasonvarga
Copy link
Member

Nice one, @jacksleight

@robdekort
Copy link
Contributor

Great stuff!

@jasonvarga
Copy link
Member

This unfortunately only "appears" to work because your default site is the one with the translation.

If you were to have multiple sites configured, and you used either feature (login form or nocache tag) from the second site, it'll show the language from the first site.

This is because the Localize middleware determines the site by the current URL.

So when you submit the form, you end up on something like /!/form-endpoint and the middleware works out the site from there.

The middleware should somehow figure out the referring URL's site, not the current one.

And that should be done without breaking it for the other places where the Localize middleware is already being used.

I'm going to close this for now, but we can reopen if this gets sorted. Either on this PR or a fresh one.

@robdekort
Copy link
Contributor

Gotcha - sorta.

For now I guess I can keep in these composer patches. I'm working on a project where localised messages are very important due to the target audience.

How can we resolve this properly though?

@jasonvarga
Copy link
Member

The Localize middleware (either the existing one, or a new one) would need to be able to look at the referring url to determine the site, instead of the current url.

@robdekort
Copy link
Contributor

Gotcha. Will open an issue for this.

@robdekort
Copy link
Contributor

Oh not needed. My previous issues reopened due to GH magic.

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.

Nocache tag not playing nice with trans tag Can't localise login:form errror/succes messages
3 participants