【问题标题】:Using Resource files for things other than language将资源文件用于语言以外的事物
【发布时间】:2015-04-28 09:45:05
【问题描述】:

我正在开发一个 MVC 应用程序,它实际上是一个中间件,用于提供外部 BPM 解决方案的管理和报告。

系统的用户并不全都用于相同的业务功能,并且可能将字段称为不同的事物(例如,部门 A 称客户为客户,但部门 B 称他们为潜在客户)。有没有办法让我拥有

的资源文件
  • Resources.divA.resx
  • Resources.divB.resx
  • Resources.divC.resx

从我的谷歌搜索来看,它似乎只能用于本地化。

【问题讨论】:

    标签: c# asp.net-mvc resources globalization


    【解决方案1】:

    您可以使用 ResourceManager 类来帮助解决此问题。

    当您将一些资源添加到项目时,IDE 会自动将Resources.Designer.cs 文件添加到项目中以管理资源。生成的代码如下所示:

    [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
    internal static global::System.Resources.ResourceManager ResourceManager {
        get {
            if (object.ReferenceEquals(resourceMan, null)) {
                global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AssemblyName.Properties.Resources", typeof(Resources).Assembly);
                resourceMan = temp;
            }
            return resourceMan;
        }
    }
    

    这使用the ResourceManager constructor that looks up resources based on a combination of a root name and the current locale

    您可以自己编写类似的代码,但根据资源是用于分区 A、B 还是 C 来计算根名称。因此您可以将其称为“AssemblyName.Resources.divA”而不是“AssemblyName.Properties” .资源”。

    然后,您还可以为其他受支持的语言设置特定版本,并且它们将自动加载(如果存在)以适应当前的文化。这就是它对 IDE 管理的资源的工作方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多