Download another css to localize the site

I need to load another css file depending on the language the user selects. I need to do this only on my main page.

+3
source share
2 answers

If you use built-in themes and globalization support, you can use httpModule: (untested)

public class PageModule : IHttpModule
{


public void Dispose()
{
}


public void Init(System.Web.HttpApplication context)
{
    context.PreRequestHandlerExecute += Application_PreRequestHandlerExecute;

}

public void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
    //Adds a handler that executes on every page request
    HttpApplication application = default(HttpApplication);
    application = (HttpApplication)sender;

    Page page = application.Context.CurrentHandler as Page;

    if ((page != null))
        page.PreInit += Page_PreInit;

}


public void Page_PreInit(object sender, EventArgs e)
{
    //If current context has no session then abort
    if (HttpContext.Current.Session == null)
        return;

    //Get current page context
    Page page = (Page)sender;

    switch (page.Culture) {
        case "en-US":
            page.Theme = "en-USTheme";
            break;
        case "fr-FR":
            page.Theme = "fr-FRTheme";
            break;
        default:
            page.Theme = "DefaultTheme";
            break;
    }

}

}
+3
source

You can write the selected language to the cookie. Then, on the main page, check the value stored in the cookie and set the correct stylesheet.

+1
source

Source: https://habr.com/ru/post/1754265/


All Articles