简体   繁体   中英

Default Resource.resx file not used

I have a WPF application which is localized.

When I set Format to Hindi(India) from ControlPanel -> Region -> Formats, Following lines of code in my WPF application at the beginning of launching of my WPF Application is not reading CultureInfo.CurrentCulture(hi-IN) instead it uses en-US.

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

Because of this, My WPF Application is not using greeting message from Resources.resx file. Instead, it is use greeting message from in Resources.en.resx

I am getting proper value in CultureInfo.CurrentCulture .

Any idea why above lines of code are not picking proper value?

The ControlPanel->Region->Formats setting doesn't apply to .resx files. It is in ControlPanel->Region->Language that you specify the default language.

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

Alternatively you could specify the default language of your resources in your App class (App.xaml.cs):

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

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

Please refer to the following link for more information: 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM