-1

I am trying to make my project multilingual. To do this, I created resource files for English and for other languages, for example:

langu.resx langu.uk-UA.resx

In some of my projects, everything works fine. But some projects don't want to change the language.

With this System.Threading.Thread.CurrentThread.CurrentUICulture returns the correct culture

I tried changing the language in the program with the following code:

ResourceManager RM = new ResourceManager("PasteCurb.Properties.Lang.langu", Assembly.GetExecutingAssembly());
              
               string day = RM.GetString("btnApplyText");

               CultureInfo ci = new CultureInfo("uk-UA");

               string dayrr = RM.GetString("btnApplyText",ci); 

But in the variable dayrr, I get the value in English, instead of Ukrainian.

Anyone have any ideas?

Andrii
  • 11
  • 2

1 Answers1

0

Set the culture info like below and than you can access a text string by the name:

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("uk-UA");              
var text = Properties.Resources.btnApplyText;

When you access resources directly by using the ResourceManager be sure that the root name of the resource file is defined correctly. By default the root name doesn't include the language identifier.

It should look like below:

var rm = new ResourceManager("PasteCurb.Properties.Resources", Assembly.GetExecutingAssembly());
string dayrr = rm.GetString("btnApplyText", new CultureInfo("uk-UA")); 

For more information see CultureInfo.CurrentCulture Property

Jackdaw
  • 7,626
  • 5
  • 15
  • 33
  • Thanks for your reply. Unfortunately it didn't help. I am writing an application for Autodesk Revit. Calling this command changed the language for other buttons (dll). But not for the problematic one. – Andrii Dec 24 '21 at 06:57
  • @Andrii: Yes, this change the culture used by the current thread. Isn't that what you want to do? You wrote: _"With this System.Threading.Thread.CurrentThread.CurrentUICulture returns the correct culture"_. So, why you are creating an additional `CultureInfo` object to load string if your thread already returns proper `CurrentUICulture`? **Update your question to describe more precisely what is you want to achieve.** – Jackdaw Dec 24 '21 at 07:10