【问题标题】:Programmatically localize a String?以编程方式本地化字符串?
【发布时间】:2011-08-18 08:10:18
【问题描述】:

Asp.net 4 和 C#。

我的代码隐藏中有一个string。我想根据用户的浏览器区域分配一个值。

我正在尝试使用此代码,没有错误,但不起作用(没有为字符串分配值)。

知道如何解决吗?谢谢

   string textPrevious = "<%$ Resources:Global, CategoryListSubCategories %>";

【问题讨论】:

    标签: c# asp.net localization globalization localizable.strings


    【解决方案1】:

    我自己找到了解决方案: 只需使用Resources.Global

    string textPrevious = Resources.Global.CategoryListSubCategories;
    

    有用的文章: http://shan-tech.blogspot.com/2007/02/aspnet-20-localization-of-string.html

    【讨论】:

      【解决方案2】:

      你可以这样做......

      string textPrevious = Resources.Global.CategoryListSubCategories;
      

      【讨论】:

      • 谢谢我找到了相同的解决方案
      • 我刚刚打字迟了,从我的一个项目中找到了与您相同的类似内容。
      【解决方案3】:

      您可以构建一个 ExpressionBuilder 来访问代码隐藏字符串。文章 .NET String Resources 包含类 StringExpressionBuilder 和表达式字符串:

      <asp:Label ID="AppTextLabel" runat="server" 
          Text="<%$ Strings:MyCompany.MyApp.MyStrings, AppText %>" />
      <asp:Label ID="LibTextLabel" runat="server" 
          Text="<%$ Strings:MyCompany.MyLib.MyStrings, LibText %>" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-31
        • 1970-01-01
        • 1970-01-01
        • 2021-07-10
        • 2013-07-31
        • 1970-01-01
        • 2019-03-21
        相关资源
        最近更新 更多