I downloaded and installed the 1.5mb file on
this page, the french localization of System.Web.Mvc.resources.
I added it as a reference to my project, added it into the assemblies of web.config, and added <globalization uiCulture="fr" culture="fr-FR" /> into the system.web section. Still, built in validation messages are coming up english. What am I missing? What
did I do wrong?
I have set the culture in the web.config, and I installed the english version of mvc from the platform installer. I cannot access the other languages from the platform installer, so I installed the resource packages from the individual download page. However,
after adding references to the localized resources, the engine still does not switch to using those strings for default .net strings, like if I use an out of the box validator. The validation message keeps coming in as english, even though I can check the
current culture and ui culture, and they are both set to french, and I have the french resource dll referenced.
meyerovb
Member
4 Points
4 Posts
Localizing mvc resources
May 16, 2011 09:48 PM|LINK
I downloaded and installed the 1.5mb file on this page, the french localization of System.Web.Mvc.resources.
I added it as a reference to my project, added it into the assemblies of web.config, and added <globalization uiCulture="fr" culture="fr-FR" /> into the system.web section. Still, built in validation messages are coming up english. What am I missing? What did I do wrong?
raduenuca
All-Star
24675 Points
4250 Posts
Re: Localizing mvc resources
May 17, 2011 06:03 AM|LINK
Have you installed it as described here:
http://haacked.com/archive/2011/05/10/localized-releases-of-asp-net-mvc-3-tools-update.aspx ?
Radu Enuca | Blog
amitpatel.it
Star
8070 Points
1880 Posts
Re: Localizing mvc resources
May 17, 2011 06:11 AM|LINK
public class BaseController : Controller { private Menuservices dbService = new Menuservices(); protected override void OnActionExecuted(ActionExecutedContext filterContext) { if (this.ControllerContext.Controller.GetType().Name != "HomeController") { if (Session["UserID"] != null && Session["UserID"].ToString().Length > 0) { } else { filterContext.Result = RedirectToAction("Index", "Home"); } } base.OnActionExecuted(filterContext); } public ActionResult Menu() { var menuItems = from t in dbService.GetMenu(0) select t; return PartialView("Menu",menuItems); } protected override void ExecuteCore() { if (Session["iLanguageId"] == null) { string browserLanguage = Request.UserLanguages[0]; if ((browserLanguage.ToString() == "en-US") || (browserLanguage.ToString() == "en-US") || (browserLanguage.ToString() == "en")) { Session["iLanguageId"] = "1"; Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); } else if ((browserLanguage.ToString() == "nl-NL") || (browserLanguage.ToString() == "nl-nl") || (browserLanguage.ToString() == "nl")) { Session["iLanguageId"] = "2"; Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-NL"); Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-NL"); } else { Session["iLanguageId"] = "1"; Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); } } else { if (Session["iLanguageId"].ToString() == "1") { Session["iLanguageId"] = "1"; Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); } else { Session["iLanguageId"] = "2"; Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-NL"); Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-NL"); } } base.ExecuteCore(); } }you can set your locallization culture in your every page by ading base controller which is inherited in every controler class...
and selecting language you need set your session....
and while fetching value... in validation you can handle it with below....
public int TeamId { get; set; } [Required(ErrorMessageResourceType = typeof(AP.Common.AP_Resources), ErrorMessageResourceName = "TeamName")] public string Name { get; set; } //// OR oMenu.DisplayName = AP_Resources.ResourceManager.GetString("Home"); //oResourceManager.GetString("<Keyname>"); oMenu.DisplayName = AP_Resources.HomeMCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
meyerovb
Member
4 Points
4 Posts
Re: Localizing mvc resources
May 17, 2011 01:21 PM|LINK
I have set the culture in the web.config, and I installed the english version of mvc from the platform installer. I cannot access the other languages from the platform installer, so I installed the resource packages from the individual download page. However, after adding references to the localized resources, the engine still does not switch to using those strings for default .net strings, like if I use an out of the box validator. The validation message keeps coming in as english, even though I can check the current culture and ui culture, and they are both set to french, and I have the french resource dll referenced.
amitpatel.it
Star
8070 Points
1880 Posts
Re: Localizing mvc resources
May 17, 2011 01:27 PM|LINK
to set different language you need to set different culture in current thread in each page is initiallization..
Hence in my code I have added basecontroller that is exectutes in each page and set culture based in session ID.
MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application