简体   繁体   English

如何使用特定区域性从App_LocalResources文件夹中的resx文件读取?

[英]How to read from a resx file in the App_LocalResources folder using a specific culture?

To read a resource for a default culture I'd do this: 要读取默认区域性的资源,我可以这样做:

object obj = GetLocalResourceObject("MyTextResourceID.Text");

But what I need is to do the same but to be able to specify a culture for the resource. 但是我需要做的只是能够为资源指定一种文化。 So I tried this: 所以我尝试了这个:

System.Globalization.CultureInfo cultInfo = 
    new System.Globalization.CultureInfo("en-US");

object obj = HttpContext.GetLocalResourceObject(
    "~/" + Path.GetFileName(this.Request.PhysicalPath), 
    "MyTextResourceID.Text", 
    cultInfo);

but it always returns obj as null. 但它总是将obj返回为null。 Any idea why? 知道为什么吗?

OK. 好。 As suggested above, I'm answering my own question. 如上所述,我在回答自己的问题。 The code above is correct and works just fine. 上面的代码是正确的,并且工作正常。 My problem was that the resource with such ID did not exist in all .resx files. 我的问题是,具有此类ID的资源并不存在于所有.resx文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM