C# – Setting WPF Program’s culture in App.config

.netapp-configc++localizationwpf

I've got a WPF application that I'm modifying to support localization. My program is part of a suite of products that my company offers. We have created a resource DLL that contains all of the strings that need to be translated for all of our products. I've added a reference to this DLL to my program, added string resources to it, and modified my code to use the string resources instead of hard-coded strings. Everything works fine when I run my program in English.

We have had the string resources translated into Spanish. I've created a resx file with the Spanish translations in it. I've rebuilt my application. Now I want to see the Spanish text appear in my program without having to change my computer's culture settings.

It's not necessary for the program to change culture settings on the fly. The program will run in one language only for a particular installation.

The program has an App.config file. Short of adding a custom setting with the culture information in it, how do I tell my program to run in Spanish?

Best Solution

You could just define a key in your App.config like this

<configuration>
    <appSettings>
        <add key="DefaultCulture" value="es-CO" />
    </appSettings>
</configuration>

and in your application read that value and set the culture

CultureInfo culture = new CultureInfo(ConfigurationManager.AppSettings["DefaultCulture"]);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;

In the example of the config I set it to Spanish-Colombia

This is a list of culture codes