-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add frontend language cookie functionality #1
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some little improvements for better readability in the future.
{ | ||
$detectedLocale = $this->localeDetector->detectLocaleFromLocaleTag($feLanguageCookie); | ||
|
||
if (!$detectedLocale instanceof Locale) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please move L150-168 to a new function and use it in both findMatchingPresetBy... methods?
Sth. like:
$detectedLocale = 'dependsOnMethod';
$preset = $this->findPresetByLocale($detectedLocale);
// For the presetByLanguageCookie one can directly return $preset.
// This check is only neccessary in the AcceptLanguageHeader while loop.
if ($preset !== null) {
return $preset;
}
// ...
Configuration/Settings.yaml
Outdated
@@ -2,3 +2,5 @@ Wegmeister: | |||
LanguageRedirect: | |||
# Add mappings for language codes if you use some different codes than the default ones. | |||
languageCodeOverrides: {} | |||
# configure the name of your frontend language cookie name | |||
feLanguageCookieName: _fe_language |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use null
as default here, because one has to implement the cookie handling for this to work. This will prevent the backend from trying to read cookies that are missing.
If you want, you can add some more information on this in the readme, but I'm also fine with the current state.
Hey I updated the code like you requested. |
In our projects we set a frontend language cookie whenever the user changes the language via the language menu.
Like that the user will always get on the language he visited last and doesn't have to switch the language everytime he revisits your website.
We think that this functionality may also be useful for others hence why we create this merge request.
Best Regards
Yannis