ASP.NET的ResourceManager读取本地的.resx [英] ASP.NET Resourcemanager to read local .resx

查看:314
本文介绍了ASP.NET的ResourceManager读取本地的.resx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的翻译我正在使用嵌入式.resx文件。有些翻译我想用另一个.resx文件,这是不嵌入覆盖(例如〜/ App_LocalResources文件/ translations.en-US.resx)。

这样做的目的是,该应用程序被编译和部署后,用户可以手动改变.resx文件重写某些嵌入式翻译

有没有使用这种正常的ResourceManager的方法吗? (在.NET 4中)

感谢您的提示


解决方案

 公共类ResxResourceManager:System.Resources.ResourceManager {
        公共ResxResourceManager(字符串baseName的,串resourceDir){
            键入[] paramTypes =新类型[] {typeof运算(字符串),typeof运算(字符串),typeof运算(类型)};
            [对象] paramValues​​ =新对象[] {baseName的,resourceDir的typeof(ResXResourceSet)};            键入BASETYPE =的GetType()基本类型。            ConstructorInfo CI = baseType.GetConstructor(
                BindingFlags.Instance | BindingFlags.NonPublic可,
                空,paramTypes,NULL);            ci.Invoke(这一点,paramValues​​);
        }    保护覆盖字符串GetResourceFileName(CultureInfo的文化){
        字符串resourceFileName = base.GetResourceFileName(培养);
        返回resourceFileName.Replace(资源,的.resx);
    }
}

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

解决方案

    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");
    }
}

这篇关于ASP.NET的ResourceManager读取本地的.resx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆