0

I have a strange behaviour in my WPF application using resources (.resx) for localization.

In Properties I created a new folder named Resources where I put my resx file. I created two files named Resources.resx and Resources.it-IT.resx.

In App class I did the overriede of method OnStartup:

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);

    Thread.CurrentThread.CurrentUICulture = new CultureInfo("it-IT");
}

What I expect is that the application starts in italian but starts in english (default in file Resources.resx).

I tried to change the name of resource for italian language from Resources.it-IT.resx to Resources.it.resx. Then I changed part where I set culture:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("it");

In this way application starts in italian.

I don't understand were's the problem. Why culture info not works with it-IT? I already tried with methods CultureInfo.GetCultureInfo and CultureInfo.CreateSpecificCulture.

Furthermore, Thread.CurrentThread.CurrentUICulture is already set as italian, but if I don't create new CultureInfo it doesn't work. Why?

I already read this question but the problem is different. I can change culture but I would like to know why it works only with TwoLetterISOLanguageName.

I tried with french (fr-FR with file Resources.fr-FR.resx) language and there's no problems.

erikscandola
  • 2,854
  • 2
  • 17
  • 24
  • What mjwills said. I set up a tiny demo application and had no trouble. Compare what you've got to the example on the link mjwills posted. Above you said, "In Properties I created a new folder named Resources where I put my resx file." I'm using VS 2017 and was not able to create a folder in Resources. I just added my resource files directly to Resources. – Jordan Wilcken Aug 19 '17 at 13:32
  • @JordanWilcken I created folder outside of properties. Then I drag and drop the folder in properties. By the way, I tried with french (`fr-FR`) and there's no problem. The problem is with italian (`it-IT`). – erikscandola Aug 19 '17 at 13:37
  • Make sure the resource file for italian has the build action set as "Embedded Resource" (right-click on the file, then properties). – Isma Aug 19 '17 at 13:49
  • @IsmaC. Build action is ok – erikscandola Aug 19 '17 at 14:20

0 Answers0