Johannes Wanzek
Johannes Wanzek

Reputation: 2875

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?

Upvotes: 17

Views: 262

Answers (1)

Shashank Chaturvedi
Shashank Chaturvedi

Reputation: 2793

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

}
}

Upvotes: 2

Related Questions