Sonam Mohite
Sonam Mohite

Reputation: 903

How to read global resource file

I have a window based application in c#. Where i am displaying some message box based on language selected.Its working fine with Form level resources but what if i want to access global resource file(project level).

ResourceManager res_man = new ResourceManager("Resources",typeof(Form2).Assembly); 
 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-SA");
        string s = res_man.GetString("String1");
        MessageBox.Show("Arabic-" + s);

I tried this but any how not working

For updated ans enter image description here

Upvotes: 2

Views: 4372

Answers (2)

Razvan Dumitru
Razvan Dumitru

Reputation: 12472

Access Modifier is by default internal. Did you use the PublicResXFileCodeGenerator ?

You can set the Access Modifier to public when you open the RESX file in Visual Studio. There is a dropdown box that can be found at the top of the form which changes the Access Modifier.

And after that you will be able to access :

var resxManager = new ResourceManager(typeof(Resource));
var currentString = resxManager.GetString("Practitioner", CultureInfo.GetCultureInfo("en-US"));

Here can be a related issue : Visual Studio - Resx File default 'internal' to 'public'

Upvotes: 2

Vikash Singh
Vikash Singh

Reputation: 814

try to change Current Culture in place of UI culture -

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ar-SA");

I am using following code for fetching specific value from Global Resource for specific culture -

ResourceManager myManager = new ResourceManager(typeof(Resources.Strings));
String currencySymbol = myManager.GetString("Currency", CultureInfo.GetCultureInfo("en-GB"));

Upvotes: 1

Related Questions