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", checkthis
questionabout 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 }
);
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.
Participant
1847 Points
1340 Posts
Culture in MVC
Oct 16, 2014 01:58 AM|rohitpundlik|LINK
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 ?
Rohit Pundlik
Please mark as answer if this helps you...
All-Star
120166 Points
27994 Posts
Moderator
MVP
Re: Culture in MVC
Oct 16, 2014 03:24 AM|ignatandrei|LINK
http://afana.me/post/aspnet-mvc-internationalization-part-2.aspx
All-Star
27134 Points
2676 Posts
Re: Culture in MVC
Feb 23, 2015 03:36 AM|Shawn - MSFT|LINK
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):
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
Participant
1471 Points
442 Posts
ASPInsiders
MVP
Re: Culture in MVC
Apr 17, 2015 04:50 PM|rstrahl|LINK
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 ---
West Wind Technologies
Making waves on the Web
weblog.west-wind.com
Check out: Markdown Monster