开发者

Programmatically localize a String?

开发者 https://www.devze.com 2023-03-29 02:43 出处:网络
Asp.net 4 and C#. I have a string in my Code Behind. I would like assign a value depending on the User\'s Browser region.

Asp.net 4 and C#.

I have a string in my Code Behind. I would like assign a value depending on the User's Browser region.

I'm trying with this code, no error, but does not work (no value to a String has bee开发者_StackOverflow中文版n assigned).

Any idea how to solve it? Thanks

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


I found out the solution myself: Just use Resources.Global.

string textPrevious = Resources.Global.CategoryListSubCategories;

Useful article: http://shan-tech.blogspot.com/2007/02/aspnet-20-localization-of-string.html


You can do like...

string textPrevious = Resources.Global.CategoryListSubCategories;


You can build an ExpressionBuilder to access the code-behind string. The article .NET String Resources includes the class StringExpressionBuilder with the expression Strings:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号