Localizing Windows Forms (text quote from MSDN)

 

  The .NET Framework uses a hub and spoke model to package and deploy resources. The hub is the main assembly that contains the nonlocalizable executable code and the resources for a single culture, called the neutral or default culture. The default culture is the fallback culture for the application. Each spoke connects to a satellite assembly that contains the resources for a single culture, but does not contain any code.

Resource Naming Conventions

When you package your application’s resources, you must name them using the resource naming conventions that the common language runtime expects. The runtime identifies a resource by its culture signature, or name. Each culture is given a unique name, which is a combination of a two-digit lowercase culture name associated with a language and, if required, a two-digit uppercase subculture name associated with a country or region. The subculture name follows the culture name, separated by a dash (-). Examples include ja-JP for Japanese in Japan, en-US for US English, or de-DE for German in Germany (as opposed to an alternate such as de-AT for German in Austria).

 

 pic1

 

Pic 1. Solution explorer

  

Retrieving Resources in Satellite Assemblies

Ideally, you should package the resources for the default or neutral assembly with the main assembly and create a separate satellite assembly for each language that your application supports. The ResourceManager class provides access to culture-specific resources at run time and controls how the application retrieves resources using the resource fallback process. You are encouraged to access resources through one of the constructors for the ResourceManager class. This requires resources to be either compiled into satellite assemblies, or a part of the application’s main assembly.

The ResourceManager determines which resources to retrieve based upon the current thread’s CultureInfo.CurrentUICulture property.

Listing 1.

 

using System.Resources;

using System.Threading;

 

namespace NamespaceName

{

    public partial class Form1 : Form

    {

 

        public Form1()

        {

            ResourceManager manager = new ResourceManager("NamespaceName.Resourcename", this.GetType().Assembly);           

            Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");

                    

            InitializeComponent();

            string text = manager.GetString("GREETINGS");  

            label1.Text = text;

        }

    }

}

 

pic2

 

Pic 2. Output directory:

 

After the build in output directory you’ll see new created directories, which names is match with the culture of the resource files.

 

See also

Packaging and Deploying Resources

Walkthrough: Localizing Windows Forms

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s