Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get string resources from specific resource file in C#

In some cases in our project we have to ignore current culture of application and get resources in English.

Basically, we do it like for all languages

<label>@ModelEntities.Properties.Resource.Gender</label>

How is it possible to get in English only?

I assume we have somehow created some reference to Resource.resx ?

I have used

 ResourceManager rm = new ResourceManager("Resource.Strings",
                     Assembly.GetAssembly(typeof(ModelEntities.Properties.Resource))); 
  var s = rm.GetString("Age");

But it seems like not working.

Thank you!

like image 567
Friend Avatar asked Oct 22 '25 23:10

Friend


1 Answers

I found the working solution.

First of all our resource files are ending like

Resource.resx

and not like Resources.resx

And in second we have resources in a separate assembly: ModelEntities

So the working code is following

var resourceManager = new ResourceManager(typeof(ModelEntities.Properties.Resource)); 
var genderString = resourceManager.GetString("Gender", ci);
like image 176
Friend Avatar answered Oct 24 '25 13:10

Friend