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

ContentRequestCultureProvider does not set cookie based on content Culture #12610

Closed
Dredy opened this issue Oct 10, 2022 · 14 comments
Closed

ContentRequestCultureProvider does not set cookie based on content Culture #12610

Dredy opened this issue Oct 10, 2022 · 14 comments

Comments

@Dredy
Copy link

Dredy commented Oct 10, 2022

Setting the ContentRequestCultureProvider "Set Cookie" on the Localization section does not sets the cookie based on the Content culture.

To Reproduce

Steps to reproduce the behavior:

  1. Create a page with Culture en-US
  2. Create the it-IT variant of the page
  3. View the en-US page
  4. Change the url to show the it-IT version
  5. The culture Picker remains on English
  6. The .AspnetCore.Culture cookie remains to en-EN

Expected behavior

I'm expecting that the Culture Picker will reflect the ContentItem.Content.LocalizationPart.Culture
and also the .AspnetCore.Culture cookie will reflect the ContentItem.Content.LocalizationPart.Culture

@Dredy Dredy added the bug 🐛 label Oct 10, 2022
@hishamco
Copy link
Member

Did you enable the Content Localization required features?

@Dredy
Copy link
Author

Dredy commented Oct 10, 2022

Yes, of course.
I'm able to create different Culture versions of any content (I've added the localization Part to any contentType).
The Culture Picker is working as expected: it changes the page to the relative Culture version, but navigating on a page with different Culture (without using the Culture Picker), the picker remains on the initial Culture and the Cookie is not updated reflecting the new culture

@hishamco
Copy link
Member

Could you please try it in a Private Window may be there's a caching issue, if the issue still we need to check then

@Dredy
Copy link
Author

Dredy commented Oct 10, 2022

Hi, i tried an "Empty cache and Hard reload", but i can confirm that it seems not to be a cache issue.
I also tried to Rebuild the project (to flush the asp.net cache) mantaining the page opened, but at refresh the picker reflects the cookie, that was with the old value.

Another info: the main menu got the Localization Part and has 2 localizations, but it does not changes the items according with the Picker. it remains always with the default Culture items

When i change the URL to the other Culture, the Picker remains on the old culture, then, if i change the culture using the Picker the page does not change (because i was already on the correct page. (that seems to work as expected)

Manually hacking the cookie value, i found that the Picker (at refresh) reads the cookie and reflects what is on the cookie, but no menu nor content reflects the new cookie value.

@Dredy
Copy link
Author

Dredy commented Oct 10, 2022

I found that there is only ONE reference to ContentRequestCultureProvider(), in the Startup.cs of OrchardCore.ContentLocalization that is responsible to setting the cookie

services.Configure(options => options.AddInitialRequestCultureProvider(new ContentRequestCultureProvider()));

Debugging i found that the DetermineProviderCultureResult is never called after the first request

Now the question is: for testing I'm using the "TheBlogTheme"
In order to set the cookie to the requested Culture, should be all the contents in a page that reflects a culture?
In other words: is the last rendered content culture that can be the problem?
For example: the "About" Page seems to have only a Page Content and a Menu, in my case both have the corresponding Culture content, but the footer has a RawHtml content that cannot have the localization part (cultures are managed inside the HTML using tags)

I'm wondering if there can be conflicts between ContentParts (some with LocaliztionPart, some without)

@hishamco
Copy link
Member

/cc @jptissot

@alafi
Copy link

alafi commented Jan 15, 2023

@hishamco
I believe this is a valid bug which was introduced by commit in src/OrchardCore.Modules/OrchardCore.Localization/Startup.cs.

The change in code is creating a new instance of RequestLocalizationOptions (inherited by OrchardCoreRequestLocalizationOptions) instead of reusing the existing one. This will ignore the configuration of RequestLocalizationOptions in Content Localization Statrup.cs which happens earlier in the initialization lifecycle.

@hishamco
Copy link
Member

I will check this one ..

@hishamco hishamco self-assigned this Jan 15, 2023
@hishamco
Copy link
Member

@Dredy I enabled OC.ContentLocalization module, then added ContentCulturePicker feature. After attaching LocalizationPart to Article content type and adding two versions, I'm able to switch between the content with expected result

@hishamco
Copy link
Member

Content.Culture.Picker.mp4

@hishamco
Copy link
Member

Furthermore we SHOULD NOT ignore the current culture provider(s)

@hishamco
Copy link
Member

For reference #13093

@Dredy
Copy link
Author

Dredy commented Jan 16, 2023

@hishamco to reproduce You have to change the url to /about-1 and /about-2
In my tests, the content changes to the required culture content, but the CulturePicker remains as it was before

@hishamco
Copy link
Member

@Dredy could you try my PR?

@sebastienros sebastienros added this to the 1.x milestone Jan 26, 2023
@sebastienros sebastienros modified the milestones: 1.x, 1.6 Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants