This project is read-only.

Help needed for localization redirection based on URL

Topics: Localization
Aug 18, 2014 at 7:11 PM
Howdy all

I am busy with integrating Orchard into a website for one of clients in the Wine industry. The requirement is that the website should be available two languages, English, the default, and Afrikaans. I have managed to make localized version of all of the content, using the Culture Switcher module to switch between the two versions.

The final problem I am facing is when a person is one culture, English, and someone sends them a link to a Afrikaans page, as in this case, TEXT. This is how the page is suppose to look if you are set to the English culture, TEXT.

Firstly, any culture specific content will not render in the first link, as the website is currently set to a different culture than what it is supposed to display.

I have tried using the same method that Culture Switcher uses when someone click on a language link but I get stuck in a page loading loop because of how Orchard caches pages.

My question is if there is any way to switch the culture, based on the url, and thus displaying the correct content for that page.

Please let me know any of this is unclear.

Thank you.
Aug 18, 2014 at 9:05 PM
Aug 19, 2014 at 6:58 AM
Hey CSADNT. Thanks for the reply. I will check out your suggestion and let you know what I come up with.
Aug 19, 2014 at 10:23 AM
Edited Aug 19, 2014 at 10:30 AM
CSADNT, I couldn't find the any specific solution in the module you posted but I managed to find a work-around for my current issue in something I had tried earlier.

To force a redirect I do a language check inside the content.cshtml and then if the contentItem's language is different to the site's language I then run a click event on the culture switcher in the main nav. I did try this method previously but got caught in a loop because of the pages being cached. This led me to the Settings -> Cache section where I changed the Default Cache Duration to 1 and I also enabled the Differentiate cultures option. This has fixed the caching issue and now when you go to a page it redirects to the localized version of it.

Thanks for you help!
Aug 19, 2014 at 12:28 PM
The module is based on orchard architecture, using selectors to fixe the current language:
I also added the possibility to adapt the priorities of each selector from the module settings, and included a notion of fallback. Concerning priorities, remember that the ‘Default Site Culture Selector’ has a fixed priority of -5. I suggest to adopt on the start something as:
Content Selector
User Selector
Browser Selector
Cookie Selector
Admin Selector

It also uses a filter on the query to fix the content to display according current selector. So if you give hightest priority to browser selector, then your user request an url for a content, the filter will detect the browser culture and look for a best fit localization for the requested contentitem.

case 1: Browser en-us , contentitem en-us and en-sp -> it display the en-us version of the contentitem
case 2: Browser en-us , contentitem only en-sp -> it display the en-sp version of the contentitem

You can also add fall-back rules, fixed or using regex
for exemple you could say for previous sample that if the browser language is not managed by the site, you fall-back to en-us version.

You were asking to display the correct culture for a page, this is doing it.