How to localize header text from .resx file?
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??
I had same issue and fixed with this solution.
-
Create own rending engine with BootstrapRenderingEngine.cs
-
Replace
sbHtml.Append(col.HeaderText)withsbHtml.Append(rm.GetString(col.HeaderText));. Create resource managerResourceManager rm = new ResourceManager(typeof(Resource)); -
Use your engine
.AddRenderingEngine("default", typeof(MyBootstrapRenderingEngine)) .WithDefaultRenderingEngineName("default") -
Replace header text
WithHeaderText(Resources.Name)with.WithHeaderText("Name") -
Fix
WithNextButtonCaption,WithPreviousButtonCaptionandWithSummaryMessagethe same way.
Edit: adding expression for header text is better solution.
Thank you so much. Your solution fixed my problem!
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?
I had same issue and fixed with this solution.
- Create own rending engine with BootstrapRenderingEngine.cs
- Replace
sbHtml.Append(col.HeaderText)withsbHtml.Append(rm.GetString(col.HeaderText));. Create resource managerResourceManager rm = new ResourceManager(typeof(Resource));- Use your engine
.AddRenderingEngine("default", typeof(MyBootstrapRenderingEngine)) .WithDefaultRenderingEngineName("default")- Replace header text
WithHeaderText(Resources.Name)with.WithHeaderText("Name")- Fix
WithNextButtonCaption,WithPreviousButtonCaptionandWithSummaryMessagethe 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?