ASP.NET Resourcemanager to read local .resx

妖精的绣舞 提交于 2019-12-22 15:03:07

问题


For my translations I'm making use of embedded .resx files. Some of these translations I wish to override with another .resx file, which is not embedded (ex. ~/App_Localresources/translations.en-US.resx).

The purpose of this is that after the application is compiled and deployed, a user could change the .resx file manually to override some of the embedded translations.

Is there a way to use the normal ResourceManager for this? (in .NET 4)

Thank you for tips


回答1:


    public class ResxResourceManager : System.Resources.ResourceManager {
        public ResxResourceManager(string baseName, string resourceDir) {
            Type[] paramTypes = new Type[] { typeof(string), typeof(string), typeof(Type) };
            object[] paramValues = new object[] { baseName, resourceDir, typeof(ResXResourceSet) }; 

            Type baseType = GetType().BaseType;

            ConstructorInfo ci = baseType.GetConstructor(
                BindingFlags.Instance | BindingFlags.NonPublic,
                null, paramTypes, null);

            ci.Invoke(this, paramValues);
        }

    protected override string GetResourceFileName(CultureInfo culture) {
        string resourceFileName = base.GetResourceFileName(culture);
        return resourceFileName.Replace(".resources", ".resx");
    }
}


来源:https://stackoverflow.com/questions/3405877/asp-net-resourcemanager-to-read-local-resx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!