Search code examples
.netwinformslocalizationvsto

Localization of Winforms VSTO with .resx files


I want to localize my VSTO winforms but I cannot get it to work. The localization does not get applied. For testing I created a very simple Winform that has only one button with some text on it.

Here is how I try to localize the text on the form:

  1. Set the .Localizable property of the form to True
  2. Use the popular ResX Manager (https://dotnetfoundation.org/projects/resx-resource-manager)) to translate my strings for the form.
  3. I also added a Strings.resx (with English and German strings) file that I try to access in the form's name via Me.Text = My.Resources.Strings.SomeRandomName

So as a result I now have a form called frmTest. Its default strings are in English but I can see that a frmTest.de.resx was created that contains my German translations.

Unfortunately the form is still shown in English and also my call to My.Resources.Strings.SomeRandomName results in an English string.

The culture is set to de-DE but I also tried manually changing it via:

System.Threading.Thread.CurrentThread.CurrentUICulture = New CultureInfo("de")

I also tried setting the office language to German which also did not help.

I found several old instructions (e.g. localisation in vsto add-in) but none of them seem to work.


Solution

  • Everything looks fine, setting Thread.CurrentThread.CurrentUICulture should be enough, but please ensure the following:

    1. You are calling Thread.CurrentThread.CurrentUICulture = New CultureInfo(...) before you open the form (I think this is obvious, but anyway)

    2. The name of the culture is the same in resources and in the CultureInfo constructor. I mean, "de" and "de-DE" is not the same thing (most probably this is the issue). I would try new CultureInfo("de-DE"), or even new CultureInfo(1031)

    Please note that office language may be different from the system language. You can use the office language using Application.LanguageSettings.LanguageID. The value should be compatible with what CultureInfo is accepting as a parameter.