Menu on Translation Layer disappearing on Custom Module Sites
Asked Answered
C

1

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?

Crinoid answered 15/4, 2015 at 5:53 Comment(5)
Do you have an example of the code for the menu, or perhaps a URL to the affected page?Linker
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...Crinoid
How is the culture resolved in your application? Is it set through the routing table and resolved from address?Galvano
Are you using a module to allow users to change their culture?Selenodont
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: "Crinoid
G
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));

}
}
Galvano answered 23/4, 2015 at 13:29 Comment(1)
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.Crinoid

© 2022 - 2024 — McMap. All rights reserved.