-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Route based Culture Provider #5125
Comments
Ok thanks for the info. I'll write a middleware for my site to deal with this situation or use a |
Cookie based approach make sense if you have the same path for the multi-lingual content item, e.g. "/about-us" that will provide English, Arabic, or French depending on the cookie. In a situation where each language version of a Content Item has their own path, cookie based approach is really confusing to user and can create embarrassing bugs. |
No need, there's already one built-in provided by Localization APIs |
Oh yeah? |
Is this the one |
I mean in ASP.NET Localization APIs not OC |
Thanks. This is my quick implementation so far using
|
|
Can you please clarify this? I am not sure what you mean by this. This is another version that makes the admin section to respect the cookie but to make the rest of the website to simply use the path. This is only relevant if at least one of your language is RTL.
|
I don't think the switch is needed, because the ASP.NET Core will do the fallback on your behalf, further more, I still prefer the built-in RCP, it will save you much time :) |
I will probably end up with RCP but it's the first time I encounter |
All the best .. I will keep this open to hear what the team thought |
Here's the thing, ASP.NET Core will do fall back from specific to general, e.g. ar-EG will fallback to ar, en-UK to en, etc. In my scenario I already setup the supported cultures to specific So I cannot return |
This is the latest iteration that actually use the culture settings from Orchard Core.
|
Also you could use Anyhow, glad you find a proper approach to solve your issue, all the best |
I think it's awesome one can reprogram the way the request culture works in less than 20 lines of additional code. |
I need this function do we have any plan or when will release this function? |
You can copy this code in our startup.cs #5125 (comment) |
@hishamco Best regards |
I thought we had this feature already, but can't find it. The solution is to implement a custom display handler, or change the existing one, so when a content is displayed, load its CultureApsect, and set the CurrentThread and CurrentUIThread culture to this. |
Maybe this one |
Yeah right this should work? |
It can't be a RequestCultureProvider because you don't know what content item is loaded and about to be displayed. But the handler should use the same IFeature to set the culture of the request. Actually I am not even sure we can use a handler, as any time something would call BuildDisplay it could change the culture. It might be set in the ItemController directly. |
Hmm, but seems that this is what the
|
So, also here it will only work if using a LocalizationPart a the content type. For example if you have your own controller that uses a domain path prefix that is the culture it won't magically make your page display in that culture. |
Yes i agree it would be just an indirect way to have "localized" route As i remember there was an mvc provider for this but not used by default, hmm and where i saw something wrong in the code but i don't remember what. I will try to find it again |
After reviewing the ContentRequestCultureProvider last night, I decided that we need to refactor this part. Reason is that a contentItemId + routeUrl is not an immutable value. The routes can be added only once in the Dictionary that adds them in the mvc routing. So it's not safe enough to say that when we search a content item by url that it will return the proper one. What we need to do here is that when we use the LocalizationPart and the AutoroutePart on a content item. The AutoroutePart pattern should be altered to include the contentItemId at the end of the url automatically. This way, we make sure that the AutoroutePart pattern stay editable, but we also make sure that we always retrieve the proper content item and it's LocalizationSet related one(s). |
One route, one content item, if it's not the case then that's a bug. Doesn't mean that two routes can't point to the same content item though, but I don't think we support that. |
Is there any built in way in Orchard Core to ensure that when someone access
https://xxx.xx/ar/education-and-scholarships/
they will get a specific culture (in this case Arabic) and when they accesshttps://xxx.xx/en/education-and-scholarships/
then will get English?The cookie based culture provider doesn't really work well when you don't start from the home page.
The text was updated successfully, but these errors were encountered: