0

我正在使用嵌入式 .resx 本地化 asp.net 应用程序。似乎不管现在的文化是什么,中立的文化资源总是被退回来的。我用来检索值的代码如下:

protected string GetResource(string name)
    {
        return Localization.ResCore.ResourceManager.GetString(name, System.Threading.Thread.CurrentThread.CurrentCulture);
    }

我在一页中指定文化是“es-PE”(秘鲁)。当我中断 GetResource 函数时,我可以验证 CurrentCulture 是“es-PE”,并且 ResourceManager 包含与此文化相对应的 ResourceSet。但是,返回的字符串始终来自中性文化集。

我嵌入的文件命名如下:

  • ResCore.resx
  • ResCore.es.resx
  • ResCore.es-PE.resx

任何帮助表示赞赏。

4

3 回答 3

1

如果要使用资源,可以将第二个参数从

System.Threading.Thread.CurrentThread.CurrentCulture

System.Threading.Thread.CurrentThread.CurrentUICulture
于 2009-08-14T09:39:44.187 回答
0

只是想知道为什么需要嵌入它?您不能只添加到 App-LocalResources 和 App-GlobalResources 并从那里使用它吗?

此外,您会发现,如果您不调用 base.InitializeCulture(),该语言将无法正常工作。您将创建一个基本页面并从中继承。像这样:

protected class BasePage : System.Web.UI.Page
{
     protected override void InitializeCulture(object sender, EventArgs e)
     {
          this.Culture = Resources.Culture = Thread.CurrentThread.CurrentUICulture;

          base.InitializeCulture();
     }
}

我希望这有帮助。

于 2009-08-05T21:54:49.910 回答
0

Why you are not using GetLocalResourceObject or GetLocalResourceObject?

于 2009-06-27T17:50:29.887 回答