How to choose one .resx file out of many to build(depending on solution configuration)?

StackOverflow https://stackoverflow.com/questions/23308678

  •  09-07-2023
  •  | 
  •  

Question

I hava a C# WPF solution that has two .resx files, one for Korean Language(Resource.resx), and the other for English Language(Resource.en-us.resx). If I build the solution I get main executable file plus one additional dll file which contains resource for en-us culture. And if I run the executable it automatically chooses language depending on which culture it is running on.

But, I want to build separate executable for each language(containing only one language data, so shows only one fixed language no matter what culture it's running on) depending on which solution configuration I choose. How can I achieve this?

Était-ce utile?

La solution

I don't think making separate EXEs is really a good idea. You could add a setting to the app.config in which you can set the culture. If you really want 2 EXEs just create another project of type WPF Application in your solution. In each project you can set the current culture at startup to the culture you want.

To set the culture you can use this code:

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");

FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), 
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(
        CultureInfo.CurrentCulture.IetfLanguageTag)));

Autres conseils

I think when you are going to build the app. Choose the resource file you want to exclude and from properties set "Build Action" value to none. Hope this solves your problem. ^_^

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top