【问题标题】:Localize ASP.NET WebForm Application using resources files使用资源文件本地化 ASP.NET WebForm 应用程序
【发布时间】:2018-12-11 20:40:51
【问题描述】:

我有基于 c# 的 ASP.NET WebForms 应用程序。

我输入了文字

<input type="text" id="txtUsername" name="username" runat="server"
       placeholder="<%$ Resources:Resource, Username %>" />

还有一个标签

<label for="Username"><%= Resources.Resource.Username%></label>

我还在 App_GlobalResources

下创建了 2 个资源文件 Resource.resx 和 Resource.en-GB.resx

Resource.resx:

用户名:用户名

Resource.en-GB.resx:

用户名:邮箱

当用户在语言之间切换时,我使用了以下代码

System.Threading.Thread.CurrentThread.CurrentUICulture = new 
System.Globalization.CultureInfo(code);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(code);
Resources.Resource.Culture = new System.Globalization.CultureInfo(code);

根据用户的选择,代码将等于 en 或 en-GB。

问题:

当我们运行项目并且代码 = en-GB 时,标签资源显示为 Resource.en-GB.resx (email) 而占位符显示为 Resource.resx(用户名).

这意味着 工作完美,而改变文化不会改变 .

有什么建议吗?

【问题讨论】:

    标签: c# asp.net webforms localization resources


    【解决方案1】:

    假设代码中的“代码”变量是文化代码:

    Thread.CurrentThread.CurrentUICulture = new CultureInfo(code);
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(code);
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 2012-06-10
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      相关资源
      最近更新 更多