Menu Item Translation with a Custom ICultureSelector

Topics: Localization
Oct 19, 2013 at 8:50 AM
Hi,

I did a simple module with ICultureSelector as Piotr Szmyd showed in his session.
I've had a LocalizationPart to MenuItem type and set a new entry for each culture.
When i set my preferred browser culture on the default culture (en-EN) everything is OK.
When i set my preferred browser culture on the secondary culture (fr-FR) i got my main page localized but the main menu deseapeared as it can't find out translation for my its menuitems.

As my project is in a hurry i have two questions :
  1. Is there a simple answer to my problem
  2. If not where should i investigate into the code to try to fix it by myself.
Regard.
Oct 20, 2013 at 2:33 PM
Edited Oct 20, 2013 at 2:52 PM
Hi,

No answer... so i continue to investigate by myself.
Here is an update on my work.
The problem is coming from WidgetFilter.OnResultExecuting(...)
Le lines of code that doesn't translate the mainmenu widget are the following
                var localizablePart = widgetPart.As<ILocalizableAspect>();
                if (localizablePart != null) {
                    // if localized culture is null then show if current culture is the default
                    // this allows a user to show a content item for the default culture only
                    if (localizablePart.Culture == null && defaultCulture != currentCulture) {
                        continue;
                    }

                    // if culture is set, show only if current culture is the same
                    if (localizablePart.Culture != null && localizablePart.Culture != currentCulture) {
                        continue;
                    }
                }
more precisely these ones
                    // if culture is set, show only if current culture is the same
                    if (localizablePart.Culture != null && localizablePart.Culture != currentCulture) {
                        continue;
                    }
When you are running on a secondary culture (not the default one ) the if condition is "true" so the widget is not rendered.
When i debug and i jump over this test i got my widget translated.

I turned out these lines of code and my site is now running well.

I'm really fresh on Orchard so i can't foresee if there is any impact with what i did.
From my point of view if somebody wrote this test it was on purpose, so i'm practically sure my "bypass" is not good.
Does any insider can confirm my diagnostic! And even better give me the right way to correct this issue.

Thank by advance.
.
Oct 21, 2013 at 9:16 PM
In similar situation from what I can understand, I created different layers from the widget menu, create a layer for each culture and select the corresponding menu for each layer.
Oct 27, 2013 at 4:01 PM
Hi

As usual when you're working with a complex framework, you do mistake due to lake of doc.
No offense to Orchard team but for new by like me it is very easy to miss a step and lose a lot of time for very little.
In my case all is coming from the fact that I added Localization to MenuItem and not to Menu :
  • I was using MainMenu only for navigation, I don’t need Localization on it but only for its MenuItem children.
  • Doing so, when orchard engine try to render Navigation it starts by the Menu so when the culture was not the default one, it skip it and don’t display the menuItems that could be localized…
    With Localization on Menu ContentType there is no bug in Orchard 1.7.1, my mistake.