We have seen in a previous article how to localize our application thanks to resources. Now here is a little trick to use these resources in a class where you can’t do dependency injection of the localization service.
Just declare a variable of System.Resources.ResourceManger with 2 parameters:
- baseName : The “path” of your targeted resource file
If my resource structure is like this:
Then the code will be :
System.Resources.ResourceManager rm = new( "PlanningWeb.Resources.PDF.report", System.Reflection.Assembly.GetExecutingAssembly() ); string myString = rm.GetString("myTitle");