locked
Culture in MVC RRS feed

  • Question

  • User52625461 posted

    Hello All,

    how to set the culture for entire mvc application without displaying the culture/language name in the URL like

    for english: www.example.com/user/create

    then if i change the language to french then the URL should be same,

    for french: www.example.com/user/create

    Only content should get displayed to French..

    How can I do this ?

    Thursday, October 16, 2014 1:58 AM

All replies

  • User197322208 posted

    http://afana.me/post/aspnet-mvc-internationalization-part-2.aspx

    Thursday, October 16, 2014 3:24 AM
  • User-1818759697 posted

    Hi,

    You could try removing the default "lang" value from the no language route, and adding a regex constant to the language route (For example allowing culture names like "en" or "en-US", check this question about a regex for culture names):

    routes.MapRoute(
        name: "Default lang",
        url: "{lang}/{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        constraints: new { lang = @"[a-z]{2,3}(?:-[A-Z]{2,3})?" }
    );
    
    routes.MapRoute(                
        name: "Default no language",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );

    For more information, you could refer to:

    http://stackoverflow.com/questions/23538361/asp-net-mvc-routing-404-when-i-remove-culture-language

    http://devproconnections.com/aspnet/aspnet-localization-working-multi-language-web-applications

    Regards

    Monday, February 23, 2015 3:36 AM
  • User1622957740 posted

    You have to track the user's preference somewhere in your application - typically with a user profile and the based on that user profile change the Culture and UI Culture. If you don't use user profiles you might also keep the user preference in a Cookie or Session state, but regardless of what you do the choice has to be stored somewhere.

    If you do use a User profile you can hook the Culture selection into your Authentication process or into the Application_PostAuthenticateRequest pipeline event once you have the user and profile information. Once you have your user profile change the thread culture and uiculture to the user's specified language.

    +++ Rick ---

    Friday, April 17, 2015 4:50 PM