The resource object with key 'Login_Username_Label' was not found. (未找到键为'Login_Username_Label的资源对象)
来源:互联网 发布:java 未来 知乎 编辑:程序博客网 时间:2024/06/05 18:37
Title:asp.net 支持多语言 国际化 网站多语言版本 The resource object with key 'Login_Username_Label' was not found.(未找到键为“X”的资源对象。)
怎么在Asp.net中支持多国语言?或者说,怎么开发一个支持多语言版本的网站?在asp.net的framework中有针对的解决方案,即使用资源文件,"怎么做?"网上有很多blog,在本文不再详细说明,我贴一篇图文并茂的blog:
ASP.NET支持多语言
本文主要针对在做国际化时,遇到的一个比较纠结的问题: The resource object with key '***' was not found.
如果vs是中文版本,那么对应的错误应该是:未找到键为"***"的资源对象。
造成这个错误的原因有一些,比如说:
1. 没有为一个key提供所有语言版本的Value,即:可能你的中文版资源文件中包含这个key,而英文版本中并没有它的定义。
2. 混淆了App_GlobalResources和App_LocalRsources的用法,即:Text="<%$ Resources:LocalizedText, Msg1 %>"与Text="<%$ Resources:Label1Resource1.Text %>"的用法。
以上两种情况可以在调试时检查出来,而我遇到的情况,比它们更为诡异!并且,我在网上找过很多帖子和博客,没有找到类似的情况,也许,你同样为此而困惑不已,接下来,将讨论我所遇到的情况。
【问题背景】
1. 在网站下,新建Asp.net文件夹(Add ASP.NET Folder) -> App_GlobalResources,分别新增两个资源文件,命名为LocalizedText-en-us.resx、LocalizedText-zh-cn.resx
2. 在两个资源文件中添加同样的name和不同语言对应的Value
3. 页面的asp:Label的Text属性设置为:Text="<%$ Resources:LocalizedText-en-us, Login_Username_Label %>"
4. 编译运行网站
问题出现了——编译发生错误,提示信息:The resource object with key 'Login_Username_Label' was not found.
【我的尝试】
我做了各种尝试:删除全局资源文件,重新输入一遍键值对;改用本地资源文件,改变调用方法;修改key的名字……
结果依然遇到这个问题,困扰了我整个下午,非常头疼!
【解决问题】
一次偶然的尝试,居然解决了这个问题,我发现我命名的资源文件跟示例中的资源文件名有些差别,我的第一段文件名中使用了"-"字符,我将"-"替换成"_",并修改了Text中指向的资源文件名,问题解决了,看来是没有找到对应的资源文件,才会导致这个问题的发生。
另外,我注意到一个问题,资源文件命名是有讲究的,"."前的部分是资源文件名,后一部分,跟各语言版本的缩写,最后才是文件后缀名,例如:
LocalizedText.resx
LocalizedText.zh-cn.resx
LocalizedText.en-us.resx
等等,因此,如果遇到同样的问题,不妨看看,是不是在最容易忽略的约定上,发生了一些错误。
- The resource object with key 'Login_Username_Label' was not found. (未找到键为'Login_Username_Label的资源对象)
- The requested resource was not found on this server
- The requested resource was not found on this server
- No resource found that matches the given name (at 'drawab' with value '@drawable/你的资源').
- (springmvc)页面找不到静态资源文件Failed to load resource: the server responded with a status of 404 (Not Found)
- the project was not built due to "a resource exists with a different case'项目位置'的错误
- struts2警告: The first TextProvider in the ValueStack could not locate the message resource with key
- thinkphp5 resource not found 未解决
- "The object cannot be deleted because it was not found in the ObjectStateManager."
- cc: 未找到命令 Command not found
- Android -- the project was not built due to a resource exists with a different case...
- 初学j2me:The MIDlet suite was not found的解决方案
- HttpServlet was not found on the Java 错误的解决办法
- org.springframework.security.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityC
- jquery:Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404 (Not Found)
- org.hibernate.WrongClassException: Object with id: 3 was not of the specified subclass
- the disk was not found(Altiris)
- ThinkPHP关于分页的使用
- 网站实现伪静态
- 网易笔试归来
- 在以普通用户打开的VIM当中以root保存
- 你是否具备了架构师的能力?
- The resource object with key 'Login_Username_Label' was not found. (未找到键为'Login_Username_Label的资源对象)
- ORA-12514 连接Oracle 10g时监听进程不能解析在连接描述符
- vim使用总结
- TEK逻辑分析或者示波器有iPad客户端就好了
- 使用日期函数高级应用的两个SQL语句
- 用十字链表存储 稀疏矩阵乘法
- C++, LUA, PYTHON, BASH混用
- java 发邮件 用org.apache.commons.mail (jar包为commons-email-1.2.jar,mail.jar)
- 2011年10月编程语言排行榜:Java人气持续走低