17

Currently I'm using Orchard 1.9 with different Main Menus on Culture Layers (en/de). For regular (translated) Content it is working.

But for Custom Modules/Pages like User/Account or MyModule/List the Menu is not appearing at all.

How can I fix this issue?

Johannes Wanzek
  • 2,717
  • 2
  • 27
  • 42
  • Do you have an example of the code for the menu, or perhaps a URL to the affected page? – JDandChips Apr 22 '15 at 09:41
  • Im sorry the URL is not public yet. There is no special code for the menu, just a "German" and an "English" Menu dependant on the current culture. it just seems that controllers doesn't "publish" the culture, so there is no culture set for the view returned from the controller. Maybe there is an attribute like `[Themed]` but for culture... – Johannes Wanzek Apr 22 '15 at 09:56
  • How is the culture resolved in your application? Is it set through the routing table and resolved from address? – Shashank Chaturvedi Apr 23 '15 at 12:52
  • Are you using a module to allow users to change their culture? – Hazza May 06 '15 at 12:15
  • No all Orchard 1.9 Native Stuff. Content is translated via CMS Backend "add translation". Currently user is changing the culture if he clicks on "translations for this site: " – Johannes Wanzek May 06 '15 at 14:15

1 Answers1

2

I am not aware of any filter that sets the attribute, but you can definitely write an action filter to do the same.

If culture is being resolved through routing, use the following code:

using System.Globalization;
using System.Threading;
using System.Web.Mvc;

public class CultureAttribute : ActionFilterAttribute {

public override void OnActionExecuting(ActionExecutingContext filterContext) {

    string language = (string)filterContext.RouteData.Values["language"] ?? "en";
    string culture = (string)filterContext.RouteData.Values["culture"] ?? "US";

    Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));
    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));

}
}

If you have culture info set in your session variables use this code:

using System.Globalization;
using System.Threading;
using System.Web.Mvc;

public class CultureAttribute : ActionFilterAttribute {

public override void OnActionExecuting(ActionExecutingContext filterContext) {

    string language = (string)filterContext.HttpContext.Session.Contents["language"] ?? "en";
    string culture = (string)filterContext.HttpContext.Session.Contents["culture"] ?? "US";

    Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));
    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));

}
}
Shashank Chaturvedi
  • 2,667
  • 16
  • 29
  • I dont know how orchard handles translation, but I don't have set the language in the URL. I just added a translation for new pages and the layers for the language. When the user now clicks on "Translations: de" the German page is loaded. So no routes here. – Johannes Wanzek Apr 24 '15 at 05:32