2

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

Sonam Mohite
  • 885
  • 4
  • 19
  • 51

2 Answers2

2

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'

Community
  • 1
  • 1
Razvan Dumitru
  • 11,815
  • 5
  • 34
  • 54
1

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"));
Vikash Singh
  • 804
  • 1
  • 10
  • 11
  • "Resources.Strings" not accessible to me and please describe what CurrencySymbol is ? – Sonam Mohite Oct 07 '14 at 06:51
  • "CurrencySymbol" is just a variable in which you hold the value. I am updating answer. – Vikash Singh Oct 07 '14 at 06:54
  • but still Resources.Strings not accessible to me. I am adding a screen shot. Please see in question panel – Sonam Mohite Oct 07 '14 at 06:57
  • "Resources.Strings" is the name of Resource file from where you want to fetch data. It will be like **Strings.en-GB.resx** in **App_GlobalResources** folder – Vikash Singh Oct 07 '14 at 06:59
  • Can you please clear one thing, if i am having two global resources files one for English and one for Arabic than ? – Sonam Mohite Oct 07 '14 at 07:03
  • make a default file with **Strings.resx** name and for specific language create file with corresponding language code. e.g. for Great Britain it will be **Strings.en-GB.resx**. Check Language code from this link - http://msdn.microsoft.com/en-us/library/ms533052(v=vs.85).aspx – Vikash Singh Oct 07 '14 at 07:11
  • Follow this link for details - http://msdn.microsoft.com/en-us/library/vstudio/ms247246(v=vs.100).aspx – Vikash Singh Oct 07 '14 at 07:12
  • You know one thing, if i add resource file Strings.resx . this is shown for "Resources.Strings" but if i rename this with "Strings.en-GB.resx" than its not accessible for "Resources.Strings" – Sonam Mohite Oct 07 '14 at 07:31
  • Having one file without any language code is mandatory. **Strings.resx** will be default for all languages. then add new resource file for each language with its corresponding language code. e.g. "Strings.en-GB.resx" – Vikash Singh Oct 07 '14 at 08:13
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62575/discussion-between-user1280492-and-vikash-singh). – Sonam Mohite Oct 07 '14 at 08:39