We need to add the globalization tag inside the web.config like the following
<globalization resourceProviderFactoryType="SLMemoryLeakSample.Web.Global.ResourceProviderFactoryExt" />
The next step is the implement the abstract class ResourceProviderFactory as follows ...
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Compilation; namespace SLMemoryLeakSample.Web.Global { public class ResourceProviderFactoryExt : ResourceProviderFactory { public override IResourceProvider CreateGlobalResourceProvider(string classKey) { //Here the ClassKey will be the TestLoaction return new CustomResourceProvider(); } public override IResourceProvider CreateLocalResourceProvider(string virtualPath) { throw new NotImplementedException(); } } public class CustomResourceProvider : IResourceProvider { #region IResourceProvider Members Dictionarydictionary; public CustomResourceProvider() { dictionary = new Dictionary (); dictionary.Add("lblName", "Name"); dictionary.Add("lblAge", "Age"); } public object GetObject(string resourceKey, System.Globalization.CultureInfo culture) { //Here the resourceKey will be the lblName //From the CultureInfo we can get the culture. return dictionary[resourceKey]; } public System.Resources.IResourceReader ResourceReader { get { throw new NotImplementedException(); } } #endregion } }
Inside the aspx page all that we have to do is the following
< >< asp:Label ID="Label1" runat="server" Text="<%$Resources:TestLoaction, lblName%>" > /asp:Label
This is post is for my friend abi
1 comments:
Thanks for the post. This helped a lot.
Post a Comment