joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
75 stars 56 forks source link

How to localize header text from .resx file? #167

Open BlazorPlate opened 6 years ago

BlazorPlate commented 6 years ago

Hello everybody! Urgent help needed please!! I want to localize Header Text value using resource file like example below cols.Add("Ordinal").WithHeaderText(Resources.Ordinal) The problem is that it always returns the default culture no matter what current culture is.

All of my grids are registered like this: protected void Application_Start() { MVCGridConfig.RegisterGrids(); } and they are only called one time after running the application and that's why it only reads the default culture after running the application.

Is there any solution for this issue??

delianenchev commented 6 years ago

I had same issue and fixed with this solution.

  1. Create own rending engine with BootstrapRenderingEngine.cs

  2. Replace sbHtml.Append(col.HeaderText) with sbHtml.Append(rm.GetString(col.HeaderText));. Create resource manager ResourceManager rm = new ResourceManager(typeof(Resource));

  3. Use your engine .AddRenderingEngine("default", typeof(MyBootstrapRenderingEngine)) .WithDefaultRenderingEngineName("default")

  4. Replace header text WithHeaderText(Resources.Name) with .WithHeaderText("Name")

  5. Fix WithNextButtonCaption, WithPreviousButtonCaption and WithSummaryMessage the same way.

Edit: adding expression for header text is better solution.

BlazorPlate commented 6 years ago

Thank you so much. Your solution fixed my problem!

snehalgiramkar commented 4 years ago

But the BootstrapRenderingEngine.cs has so many references to other class files like interface and model classes. Do I need to copy all those in my solution? I am using ASP.Net and have installed this using nuget package manager. There is no point copying existing files and changing code. Is there any easy solution for this? I need to replace the Header text with Resource file data.

You mentioned Edit: adding expression for header text is better solution. How to do this?

snehalgiramkar commented 4 years ago

I had same issue and fixed with this solution.

  1. Create own rending engine with BootstrapRenderingEngine.cs
  2. Replace sbHtml.Append(col.HeaderText) with sbHtml.Append(rm.GetString(col.HeaderText));. Create resource manager ResourceManager rm = new ResourceManager(typeof(Resource));
  3. Use your engine .AddRenderingEngine("default", typeof(MyBootstrapRenderingEngine)) .WithDefaultRenderingEngineName("default")
  4. Replace header text WithHeaderText(Resources.Name) with .WithHeaderText("Name")
  5. Fix WithNextButtonCaption, WithPreviousButtonCaption and WithSummaryMessage the same way.

Edit: adding expression for header text is better solution.

But the BootstrapRenderingEngine.cs has so many references to other class files like interface and model classes. Do I need to copy all those in my solution? I am using ASP.Net and have installed this using nuget package manager. There is no point copying existing files and changing code. Is there any easy solution for this? I need to replace the Header text with Resource file data.

You mentioned Edit: adding expression for header text is better solution. How to do this?