Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menu on Translation Layer disappearing on Custom Module Sites

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?

like image 860
Johannes Wanzek Avatar asked Apr 15 '15 05:04

Johannes Wanzek


1 Answers

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));

}
}
like image 106
Shashank Chaturvedi Avatar answered Oct 09 '22 09:10

Shashank Chaturvedi