【发布时间】:2010-07-05 20:54:24
【问题描述】:
我在获取正确的资源文件条目时遇到问题,需要一些帮助...这是我的方案
我有一系列项目属于遵循这种格式的大型报告解决方案
插件.****报告
- 参考(文件夹)
- DataAccessLayer(文件夹)
- 数据集(文件夹)
- DataWrappers(文件夹)
-
本地化(文件夹)
*.cs
其中 * 是我要生成的报告的名称
*.cs 有一个导出语句,因此我可以使用 MEF 来获取它(不确定这是否相关,但认为值得一提)。 *.cs 中的命名空间是 CompanyName.DataShaper.Plugin.*Report。由于项目名称和文件位置,我将每个项目的默认命名空间更改为 CompanyName.DataShaper.Plugin.*Report(在我更改之前它只是 Plugin.*Report)。
现在问题.. 在 *.cs 内部我正在实例化一个 ResourceManager。看起来是这样的……
_resourceManager =
new ResourceManager("CompanyName.DataShaper.Plugin.*Report.Localization.*Report",
Assembly.GetExecutingAssembly());
在我的 resx 设计器文件中,我有以下...
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CompanyName.DataShaper.Plugin.*Report.Localization.*Report", typeof(*Report).Assembly);
resourceMan = temp;
}
return resourceMan;
}
我对资源管理器的调用如下所示...
string resourceString = _resourceManager.GetString(resourceKey, _currrentCultureInfo);
其中 _currentCultureInfo 是一个正确的 CultureInfo 对象。
我的本地化文件夹中有 4 个不同的 resx 文件,用于每个项目(****Report.resx、****Report.fr-ca.resx、****Report.en-gb.resx、 ****Report.de-de.resx)。
当我调用资源管理器时,我总是从 .resx 中获取条目……从来没有任何其他语言文件,无论我传递给调用的 CultureInfo 对象是什么。我搞砸了什么?
--> 快速更新我原来的问题,但这似乎与 MEF 相关。我用老式的方式(new *Report())实例化了我的类并进行了本地化调用,它工作正常
【问题讨论】:
-
* 是怎么回事?您真的构建了附属程序集吗?
-
我有大约 20 个不同的项目,它们都遵循相同的命名约定。 * 仅代表报告名称。例如,其中之一是 TransactionReport.cs .. 所以有 TransactionReport.res、TransactionReport.en-gb.resx、Plugin.TransactionReport 等。
标签: c# .net localization mef resourcemanager