OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.37k stars 2.38k forks source link

How to use Culture Picker with custom controllers #8113

Closed craftyweb closed 4 months ago

craftyweb commented 3 years ago

HI, I have a multilingual website with translations of content items, but I have also custom pages via controllers. Is it possible to redirect to the correct url via the Culture Picker shape?

Example of what I get now:

I go to the overview page of my webshop. ~/en/webshop

The English translations of the product are shown.

When I change the culture with the Culture Picker to Dutch the Dutch translations are shown, but the url is still ~/en/webshop instead of ~/nl/webshop

What am I doing wrong? What is the easiest way to fix this?

Thanks!

hishamco commented 3 years ago

@jptissot is there anything to make this happen, I remembered we can use alias pattern for that

craftyweb commented 3 years ago

@hishamco Would be great if you have an example of that. Now I define custom routes in my StartUp.cs class. I use the pattern {culture}/webshop/{controller}/{action} to go to the correct controller and action in the correct culture

jptissot commented 3 years ago

Hmm I am not familiar with the pattern when using custom controllers. I would need more information about your CulturePicker implementation.

craftyweb commented 3 years ago

@jptissot I’ve made a custom feature to override the ContentCulturePicker shape so when I click on a culture I will go to a custom controller.

In this controller I would like to check if there is a culture in the url. Then I would like to redirect to the same url with a different culture.

example: I’m on ~/en/webshop and I select “nl” from the culture picker. The controller received ~/en/webshop as url and “nl” as targetCulture. Then I would like to redirect to ~/{targetCulture}/webshop.

sebastienros commented 3 years ago

In this controller I would like to check if there is a culture in the url. Then I would like to redirect to the same url with a different culture.

Isn't it exactly what the current culture picker and its associated controller already do?