Use module with links

Topics: General
Apr 6, 2011 at 6:53 AM
Edited Apr 6, 2011 at 6:58 AM

I want to use your module with links to change culture. Tried 

<ul>
@foreach (var item in availableCultureswithNames) {
    <li>
        @Html.ActionLink(item.Value, "ChangeCulture", "UserCulture", new { Area = "Orchard.CulturePicker" }, null);
    </li>
}
</ul>

in CulturePicker.cshtml but it will never work. How to pass the culture via actionlink?

Coordinator
Apr 6, 2011 at 9:34 AM
Edited Apr 6, 2011 at 9:47 AM

First of all, you need to pass culture name to the route values:

@Html.ActionLink(item.Value, "ChangeCulture", "UserCulture", new { Area = "Orchard.CulturePicker", CultureName = item.Key }, null)

But unfortunately ChangeCulture controller action accepts only POST requests currently, so you can`t use anchor element for submitting data. I will fix it soon.

If you need this urgently, you can just remove HttpPost attribute from the controller action definition:

public ActionResult ChangeCulture(string cultureName) {
Apr 6, 2011 at 4:33 PM

Thank you. Nice work.

Apr 7, 2011 at 11:41 AM

I ld like user to select the language on HomePage and redirect him to a second one localized. When user return to site i'ld like to check if there is a cookie and redirect to the second localized page automatically.

Is it possible?

Coordinator
Apr 7, 2011 at 1:05 PM
Edited Apr 7, 2011 at 1:06 PM

Unfortunately, Culture Picker resolves such requests for the home page only. Example:

  1. User culture is German.
  2. User requests "http://yourwebcsite/" url.
  3. CulturePicker checks if there is a German version of this page exists, and automatically redirects user to "http://yourwebsite/de-DE".

This rule works for the home page only, and does not work, if you are trying to resolve "http://yourwebsite/products", for example. The reason for this was to let search engines to index content of the localized pages, but now I see that we need more sophisticated approach, based on the culture cookie.

Apr 7, 2011 at 4:09 PM

What about localized menu? How it works?

Coordinator
Apr 7, 2011 at 4:17 PM
Edited Apr 7, 2011 at 4:18 PM

If you disable CulturePicker and take a look at the main menu, you will see, that menu items for all languages are displayed. Each menu item points to the corresponding route. So, I simply override MainMenuNavigationProvider, which is responsible for retrieving menu items, with my own implementation (LocalizableMainMenuNavigationProvider), that filters menu items based on the current user culture.

Oct 4, 2011 at 3:43 PM
ermakovich wrote:

Unfortunately, Culture Picker resolves such requests for the home page only. Example:

  1. User culture is German.
  2. User requests "http://yourwebcsite/" url.
  3. CulturePicker checks if there is a German version of this page exists, and automatically redirects user to "http://yourwebsite/de-DE".

This rule works for the home page only, and does not work, if you are trying to resolve "http://yourwebsite/products", for example. The reason for this was to let search engines to index content of the localized pages, but now I see that we need more sophisticated approach, based on the culture cookie.

Do you still have plans to fix this?

Coordinator
Oct 5, 2011 at 9:36 AM

Hi,

Yes, I have plans to implement this feature, but I'm too busy currently with another projects, so I can't provide any information regarding dates.

Oct 5, 2011 at 3:11 PM

Thanks. We have a need for culture selection that actually works, for a pretty big Microsoft project, and your work seems to be the best option out there. Keep it up, and thanks for what you've done so far :)