How to localize Grid.MVC

Mar 28, 2014 at 6:41 PM
Am I the only one who doesn't get how to localize the grid? I included gridmvc.lang.ru.js in my ASP.net script bundle and changed my browser language to Russian [ru-RU]. Using developer tools, I've verified that the script file is included in my rendered page, but the filter options (Equals, StartsWith, etc.) still show in English. Is there some additional wiring I'm missing?

Thanks in advance!
Coordinator
Apr 5, 2014 at 7:33 AM
Hi

By default grid tries to use current culture. For this you need to copy sallelite libraries in your project. Unfortunatly there is no nuget packages for this. You can download source code and build it manually from https://gridmvc.codeplex.com/SourceControl/latest (you need to copy /bin/ru folder to your project). I recommed you to do this, if you want to support multiple languages/

Then you can determine current client and override current thread culture:
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (Request.UserLanguages != null)
            {

                // Validate culture name
                string cultureName = Request.UserLanguages[0]; // obtain it from HTTP header AcceptLanguages
                if (!string.IsNullOrEmpty(cultureName))
                {
                    // Modify current thread's culture            
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName);
                    Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(cultureName);
                }
            }
            base.OnActionExecuting(filterContext);
        }
Please see the repository sample at https://gridmvc.codeplex.com/SourceControl/latest#GridMvc/GridMvc.Site/Controllers/ApplicationController.cs and deployed version at http://gridmvc.azurewebsites.net/

Also you have a SetLanguage method to setup culture manually:
@Html.Grid(....).SetLanguage("ru")
Marked as answer by steveosmith on 4/7/2014 at 11:44 AM
Apr 7, 2014 at 6:44 PM
Fantastic! I now have the grid beautifully localized!! Thanks for your reply!!