Localization using a resource file does not work

I added a new Rosource UserNotification.resx file. Then I added two files for localization and named them UserNotification.hr-HR.resx and UserNotification.sl-SI.resx. (follow thread: How to use localization in C # )

Then I changed the Windows language to "si". If I print the current culture using System.Globalization.CultureInfo.CurrentCulture.ToString() , the output is si sl-SI

But I always get a string from UserNotification.resx. Seams do not recognize localization resource files.

+2
source share
1 answer

The problem with .NET localization, if you use multithreading, is that you need to manually set the culture for each thread that you create (in case it is different from the Windows culture if the user can select the desired language). It is not inherited from the main stream.

After creating a new thread and before starting it, you must install it in the Main thread Culture (which normaly uses the standard culture for windows).

So, the system shows a good CurrentCulture. But what does the current thread say? Maybe the application starts with a different culture for some reason, so why does it load the default resource file? In any case, there is no reason why you should not manually tune the current culture. Basically, you need to do this when you want to give the user the opportunity to change the language of the application.

+5
source

Source: https://habr.com/ru/post/1436810/


All Articles