0

I have an application written in C# that I have translated in several different languages. Up until now, it has been correctly detecting the language from the Operating System's UI Culture and displaying all menus (etc) in that language.

Recently, however, I have recompiled the application (after no notable changes in the area of languages/culture) and it always seems to be defaulting in English, despite the CurrentUICulture clearly being something else (for example, fr). I am at a loss to figure what is causing the problem. If I explicitly set the culture like so (in the main form's constructor), everything works:

// Explicitly set UICulture, even though it's already fr-FR
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");

Does anyone have any idea what is going on? I thought it may have been an issue with Visual Studio, however I have tried to recompile on both VS2013 & 2015 and have the same problem.

Thanks.

EDIT: Additional information: This is a WinForms desktop-application which is currently targeting the .NET v3.5 framework. The behaviour has been observed under Windows 10 (could there have been a recent Win10 update causing this, perhaps?)

Veve
  • 6,643
  • 5
  • 39
  • 58
Simple Guy
  • 568
  • 5
  • 21
  • Are you sure you're calling it on the gui thread? – Jeroen van Langen Sep 20 '16 at 21:11
  • Is this a web application or a desktop application or a console application? – Uwe Keim Sep 20 '16 at 21:15
  • Hi Jeroen, if I show a MessageBox just above the explicit set of the CurrentUICulture code shown above, the CultureInfo reports "fr-FR". Uwe - this is a desktop application. – Simple Guy Sep 21 '16 at 06:34
  • Is the culture consistent, i.e. CurrentCulture and CurrentUICulture the same? Happened to struggle with that, see http://www.codeproject.com/Feature/WeirdAndWonderful.aspx?msg=5300655#xx5300655xx – Bernhard Hiller Sep 21 '16 at 08:02
  • Hi Bernhard, thanks for your input. I'm not sure if the link helps. There is a case that CurrentCulture and CurrentUICulture can be different. This doesn't seem to answer the question why CurrentUICulture needs to be explicitly set (at no stage does CurrentCulture need to be explicitly set to change the UI display language).. – Simple Guy Sep 22 '16 at 14:57
  • Most obvious reason is that your OS' default UI language changed to English. It might still look like French because you don't have the English MUI pack installed. If you don't know how to use the Language applet in Control Panel (it is getting convoluted) then ask for help at superuser.com – Hans Passant Sep 22 '16 at 15:37
  • Hi Hans - here's the conundrum: I can run an older version of the application and it works fine. The newer version requires that CurrentUICulture be explicitly set. For the record, I can search the entire solution for CurrentUICulture and at no stage is the setter being used (except when I try to work around the bug as mentioned in the original outline of the problem). – Simple Guy Sep 22 '16 at 21:02

2 Answers2

1

I finally found the issue and fix. I was creating a build from MSBUILD and it seems this issue was a result of not explicitly targeting a specific framework version (v3.5 in my case). This means that the application was getting built in v3.5 and the satellite assemblies were being generated in v4.0 (not sure why the difference). This was causing them not to load correctly. (Incidentally, the application worked fine when it was built in the VS IDE with the same solution file.)

The solution is to explicitly target the framework (with msbuild /tv:3.5 switch in my case) and make sure that all the resulting language assemblies are in the same framework version. Failure to do this means that the language just won't load and the default language will be used instead.

Simple Guy
  • 568
  • 5
  • 21
0

I'll take a shot in the dark on this one.

Have you recently added asynchronous programming to the application? If so, check what version of the framework you are on, as the culture is likely not being preserved on spawned threads. I believe the latest version can support this, but I haven't verified that personally.

Mark D
  • 3,317
  • 1
  • 26
  • 27
  • Thanks for the suggestion, Mark, but no - no additional threads have been spawned. If I show a MessageBox just above the explicit set of the CurrentUICulture code shown above, the CultureInfo reports "fr-FR". – Simple Guy Sep 21 '16 at 06:34
  • Can you be more specific about what isn't being translated? Is it Resource-file-based? – Mark D Sep 21 '16 at 22:41
  • Hi Mark - yes, it is a resource-based file (resx). We are talkign WinForms here whereby I set the "Language" field in the VS UI editor and then proceed to edit the various labels on the form in the chosen language. – Simple Guy Sep 22 '16 at 14:58