【问题标题】:Default Resource.resx file not used未使用默认 Resource.resx 文件
【发布时间】:2017-03-05 15:04:37
【问题描述】:

我有一个本地化的 WPF 应用程序。

当我从 ControlPanel -> Region -> Formats 将 Format 设置为 Hindi(India) 时,在我的 WPF 应用程序启动开始时,我的 WPF 应用程序中的以下代码行不是读取 CultureInfo.CurrentCulture(hi-IN) 而是它使用 en-US。

Application.Current.MainWindow = new MainWindow();
Application.Current.MainWindow.Show();

因此,我的 WPF 应用程序没有使用来自 Resources.resx 文件的问候消息。相反,它使用 Resources.en.resx 中的问候消息

我在CultureInfo.CurrentCulture 中获得了适当的价值。

知道为什么上面的代码行没有选择正确的值吗?

【问题讨论】:

  • 非凡的主张需要非凡的证据,我没有看到任何证据。就像 .NET 区分 CurrentCulture 和 CurrentUICulture 一样,操作系统也是如此。因此,您可能更改了系统区域设置,但没有更改显示语言。或者您可能忘记注销+登录以使更改生效。在 superuser.com 上寻求正确配置的帮助

标签: c# .net wpf localization globalization


【解决方案1】:

ControlPanel->Region->Formats 设置不适用于 .resx 文件。您可以在 ControlPanel->Region->Language 中指定默认语言。

What is the difference between CurrentCulture and CurrentUICulture properties of CultureInfo in .NET?

或者,您可以在 App 类 (App.xaml.cs) 中指定资源的默认语言:

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        Resources.Culture = System.Threading.Thread.CurrentThread.CurrentCulture;
    }
}

更多信息请参考以下链接:https://social.msdn.microsoft.com/Forums/vstudio/en-US/6bfb8d13-3a86-4c10-a632-bb20c99d0535/localization-in-wpf-using-resx-files-for-different-languages?forum=wpf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    相关资源
    最近更新 更多