使用的ResourceManager [英] Using ResourceManager

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

问题描述

我试图使用ResourceManager在C#类,但不知道创建ResourceManager类的新实例时什么来取代基名。

I'm trying to use the ResourceManager in a C# class, but don't know what to substitute for the basename when creating a new instance of the ResourceManager class.

我有一个包含由我的上述项目命名为以下引用的资源文件的一个单独的项目:
•Resources.resx
•Resources.es-ES.resx

I have a separate project that contains the resource files which is referenced by my project above named as the following: •Resources.resx •Resources.es-ES.resx

如果我有一段代码如下,我应该怎么取代基名时,我想用英语或资源的西班牙语版本?

If I have a code snippet as follows, what should I substitute for the basename when I want to use the English or Spanish version of the resources?

ResourceManager RM = new ResourceManager(basename,Assembly.GetExecutingAssembly());



我试过由汤姆提议的做法,但我得到了臭名昭著的错误找不到合适的任何资源指定区域性或中性文化。

I tried the approach suggested by Tom, but am getting the infamous error "Could not find any resources appropriate for the specified culture or the neutral culture".

我有2个项目中的项目YeagerTech是一个Web应用程序项目和项目YeagerTechResources是包含所有资源的一个项目(在相同的溶液)。项目YeagerTech具有它YeagerTechResources参考。

I have 2 projects where project YeagerTech is a web application project and project YeagerTechResources is a project (in the same solution) that contains all the resources. Project YeagerTech has a reference in it to YeagerTechResources.

我创造我的资源管理器时的语法如下:

I have the following syntax when creating my Resource Manager:

ResourceManager RM = new ResourceManager("YeagerTechResources.Resources", Assembly.GetExecutingAssembly());



显然,这是不正确。

Obviously, it's incorrect.

在YeagerTechResources项目的资源文件有自己的BuildAction的设置为嵌入的资源。

The resource files in the YeagerTechResources project have their BuildAction set to Embedded Resource.

我的资源文件的名称是:Resources.resx和Resources.es-ES.resx。

The name of my resource files are: Resources.resx and Resources.es-ES.resx.

如果有人可以简单地告诉我确切的语法实例化的资源管理器时使用基于我的项目和资源文件的名字,我将不胜感激...

If someone can simply tell me the exact syntax to use based on my project and resource file names when instantiating the resource manager, I would greatly appreciate it...

我所做的一切,我能想到的解决这一点,并不能....

I've done everything I can think of to resolve this and can't....

这是我最后一次尝试在这里解决它......

This is my last attempt to resolve it here...

ResourceManager RM = new ResourceManager("YeagerTechResources.Resources", Assembly.GetExecutingAssembly());



我执行下面的代码后发现了以下错误:

I am getting the following error after executing the following code:

sb.Append(RM.GetString("RegisterThanks"));



找不到适合指定区域性或中性文化的任何资源。确保YeagerTechResources.Resources.resources正确嵌入或在编译时链接到程序集YeagerTech,或者确保所有需要的附属程序集都可加载并完全签名。

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "YeagerTechResources.Resources.resources" was correctly embedded or linked into assembly "YeagerTech" at compile time, or that all the satellite assemblies required are loadable and fully signed.

我有一个解决方案和两个项目。一个是web项目,另一个是资源的项目。资源项目包含为在Web项目的引用。

I have one solution and two projects. One is the web project and the other is the resources project. The resources project is contained as a reference in the web project.

我可以在HTML标记使用的资源完全没有问题,但来到C#时在控制器代码中,我不断收到上述错误。

I am able to use the resources in the HTML markup with absolutely no issues, but when coming to the C# code in the Controller, I keep on getting the above error.

任何帮助的确切语法我根据我的项目将不胜感激需要。

Any help for the exact syntax I need based on my projects would be greatly appreciated.

推荐答案

有由字符串的阅读资源极其简单的方式:

There's surprisingly simple way of reading resource by string:

ResourceNamespace.ResxFileName.ResourceManager.GetString("ResourceKey")

它的清洁和优雅的解决方案通过这里的点号不能使用(例如,当资源键在数据库中持久化)键的阅读资源。

It's clean and elegant solution for reading resources by keys where "dot notation" cannot be used (for instance when resource key is persisted in the database).

这篇关于使用的ResourceManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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