简体   繁体   中英

Localization does not work on some projects

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?

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")); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM