1

I have two .resx files for localization - Global.en.resx and Global.resx(ru). Trying to get the value by name using ResourceManager I face a problem: the value displays only on Russian.

ResourceManager rm = new ResourceManager(resourceType.FullName, resourceType.Assembly);
ResourceSet rs = rm.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry d in rs)
{
    if (d.Key.ToString() == propName) displayName = (string)d.Value;
}

resourceType - resources class, propName - the name of property I want to display. Please, help me

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
ivanblin
  • 120
  • 10
  • Is the current culture English or Russian? Going by the names of your resource files I would guess that the current (default) culture is Russian... – Ron Beyer Jul 15 '15 at 14:12
  • I change current culture and it works fine when I just display it from view using @MyResources.Global.PropertyName. But when I try to get value using reflection it fails like described above – ivanblin Jul 15 '15 at 14:38
  • Its confusing, because the example you posted does not have any kind of reflection in it at all, so were are you using reflection? In the example you posted, you are getting the **current** culture, which is probably Russian, and it will work if you change the **current** culture, but if you want a different culture returned, you can't pass in `CultureInfo.CurrentCulture` to the `GetResourceSet`, you need to make an English culture and pass that in. – Ron Beyer Jul 15 '15 at 14:50
  • Actually I use reflection to get ResourceType, but I didn't post it here. Anyway, you are absolutely right. I checked my Thread.CurrentThread.CurrentUICulture and its value was "ru" for some reasons. Thanks! – ivanblin Jul 15 '15 at 15:06

1 Answers1

0

When you say you try to get the value by name, are you referring to the ResourceManager? You can get the ResourceManager in any way you can, but you are getting the ResourceSet by CultureInfo, not name. That is your issue.

Bsa0
  • 2,631
  • 5
  • 17
  • 23
  • What do you mean? If you are talking about rm.GetString(propName), I tried this way too but it displays not value of property, it displays name of property (what is double strange) – ivanblin Jul 15 '15 at 14:42