0

我在使用资源文件时遇到了一个非常奇怪的问题。

我有一个包含很多 aspx 站点的 ASP.NET Web 应用程序。我为每个 aspx 页面生成了本地资源文件,并进行了复制/重命名,然后进行了翻译。现在我有例如页面 SamplePage.aspx 和资源文件 SamplePage.aspx.resx(原始,克罗地亚语)和 SamplePage.aspx.en.resx(英文翻译)。

当我在后面的代码中更改 currentculture/currentuiculture 时,一切正常 - 单词是从新选择的区域的 resx 文件中加载的,但是有些部分仍未翻译,而是从另一个 resx 文件中加载的。

我注意到只有 asp:dropdownlists、asp:radiobuttons 和 asp:buttons 翻译得不好,所有标签和段落都可以。

这些控件的 meta:resourcekey 标签设置正确,就好像我将一个按钮的文本更改为资源文件中的其他内容一样,更改在那里并且在线可见,但它仍然是从错误的资源文件加载的。

什么可能导致问题?

这和我改变地区有什么关系吗?它目前在 OnInit 中。

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        string culture = "hr-HR";
        //string culture = "en-US";

        Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
        Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture); 
    }
4

1 回答 1

0

在以下示例 (VB.NET) 中,语言在 Global.asax 中设置

Sub Application_BeginRequest(sender As Object, e As EventArgs)
    Dim c As New CultureInfo("en-US")
    Thread.CurrentThread.CurrentCulture = c
    Thread.CurrentThread.CurrentUICulture = c
End Sub

通常,对于整个 Web 应用程序,每种语言应该只有 1 个 .resx 文件。

于 2015-02-03T13:38:30.020 回答