Search code examples
c#.netwinformsglobalization

Multiple Form Globalization


We have a large solution with 100+ forms which all have labels and buttons etc... in English.

All the forms have common text on them, say for example there is the word "Job" on at least 20 forms.

We are looking to move towards a different market and require that the forms are all in different languages. Having looking into .NET globalization techniques we have found that the standard approach does not suit us that well; That approach being a coded solution. We want to avoid replicating

button.Text = ResourceManager.getString("job");`

in 20+ forms and were looking to see if there is a simpler solution. (We set the culture on application startup)

One that we had an idea of was a resx (resource file) that we can bind to the forms and then select a value in that resource file to bind to a label or button text. As far as we can tell we can't find a simple solution like this.

We know that we can create .resx files behind each form, but this is too much overhead if we want to include more languages in the future - and also there is unnecessary duplication when the word "Job" is on more than one form.

Does a solution exist where we can bind a resource file (or Satellite Assembly) to each form/component (without code) and then just select what value we want displayed? Or are there alternative solutions which are similar?


Solution

  • In the end, because of the size of the project, we had to use a coded solution.

    We added in a new solution and this just contained resource files that contained all the languages we used as well as a default set (English).

    In the constructor of each page we changed all the component text values by using

    job_label.Text = LanguageResources.job; //example to display "job" on a label
    

    Because Visual Studio creates strong-typed classes for the resource files we can directly call the resource file LanguageResources and access any field in it. Then we created LanguageResources.de-DE.resx and populated that with all the same keys as the English version but with German values.

    Thanks to .NET's Globalization techniques, we can set the language in the .config file so that when the application runs it can check to see what language it needs to display and accesses the appropriate resource file. If the language is unrecognized it will default to English.