ResourceManager 未拾取正确的 resx 文件
我在获取正确的资源文件条目时遇到问题,需要一些帮助...这是我的场景
我有一系列项目,它们是遵循此格式
插件的大型报告解决方案的一部分。****报告
- 参考(文件夹)
- DataAccessLayer(文件夹)
- DataSets(文件夹)
- 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 对象。
我的每个项目的 Localization 文件夹中有 4 个不同的 resx 文件,(****Report.resx、****Report.fr-ca.resx、****Report.en-gb.resx、*** *Report.de-de.resx)。
当我调用资源管理器时,我总是从 .resx 中获取条目...从来没有任何其他语言文件,无论我传递到调用中的 CultureInfo 对象如何。我搞砸了什么?
-->快速更新我原来的问题,但这似乎与 MEF 相关。我以老式方式实例化了我的类(新的 *Report())并进行了本地化调用,它工作正常
I am having an issue getting the correct resource file entries and need some help ... here is my scenario
I have a series of projects that are a part of a large reporting solution that follow this format
Plugin.****Report
- Reference (folder)
- DataAccessLayer (folder)
- DataSets (folder)
- DataWrappers (folder)
Localization (folder)
*.cs
Where * is the name of the report I am going to generate
The *.cs has an export statement so that I can pick it up using MEF (not sure if this is relevant, but thought it worth mentioning). The namespace in *.cs is CompanyName.DataShaper.Plugin.*Report. Due to the project name, and location of the files, I changed the default namespace for each project to be CompanyName.DataShaper.Plugin.*Report (it was just Plugin.*Report before my change).
Now for the problem .. inside of *.cs I am instantiating a ResourceManager. That looks like this ...
_resourceManager =
new ResourceManager("CompanyName.DataShaper.Plugin.*Report.Localization.*Report",
Assembly.GetExecutingAssembly());
inside my resx designer file I have the following ...
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;
}
My call to the resource manager looks like this ...
string resourceString = _resourceManager.GetString(resourceKey, _currrentCultureInfo);
where _currentCultureInfo is a a correct CultureInfo object.
I have 4 different resx files in my Localization folder for each project, (****Report.resx, ****Report.fr-ca.resx, ****Report.en-gb.resx, ****Report.de-de.resx).
When I make the call to the resource manager, I always get the entry from the .resx ... never any of the other language files, regardless of the CultureInfo object I pass into the call. What have I messed up?
--> Quick update to my original question, but this does appear to be MEF related. I instantiated my class the old fashioned way (new *Report()) and made the localization call and it works fine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我想通了。我得到了 .resx 文件,因为它真正嵌入到主程序集中。其他文件被构建到每种语言的单独 dll 中,然后我需要将它们复制到我构建聚合容器的同一文件夹中,然后我的资源管理器可以看到所有语言。
OK, I figured this out .. I am getting the .resx file because it is truly embedded into the main assembly. The other files are getting built into separate dlls for each language, I then need to copy them into the same folder that I build my aggregate container from, my resource manager then sees all languages.