views:

164

answers:

2

Hello,

what I have is the currencyIsoCode "EUR". This Property can also be found in the

RegionInfo class => ri.ISOCurrencySymbol. But the RegionInfo class depends on the current logged in user.

What I want is to get the NativeEnglishName like "Euro" even when the user is from en-De, en-Us, cn-CN etc...

How can I do that?

+1  A: 

Awkward problem, there is no easy way to iterate the available RegionInfo. You'd have to iterate all available specific cultures and create their RegionInfo to compare. This code gets the job done:

public static string GetEnglishCurrencyName(string iso) {
  foreach (var c in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) {
    var reg = new RegionInfo(c.LCID);
    if (string.Compare(iso, reg.ISOCurrencySymbol, true) == 0)
      return reg.CurrencyEnglishName;
  }
  throw new ArgumentException();
}

Beware that this generates a lot of garbage. If you do this often, be sure to cache the region info in a Dictionary<> first.

Hans Passant
this is my solution same as yours nobugZ: private string GetNativeCurrencyName(string currencyISOCode) { CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); foreach (CultureInfo ci in cultures) { RegionInfo ri = new RegionInfo(ci.LCID); if(ri.ISOCurrencySymbol.Equals(currencyISOCode,StringComparison.CurrentCultureIgnoreCase)) return ri.CurrencyEnglishName; } return string.Empty; }
msfanboy
found the solution here: http://bytes.com/topic/net/answers/519499-currency-localization-issue
msfanboy
+1  A: 

You can do:

string currencyName = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
                   .Where(c => new RegionInfo(c.LCID).ISOCurrencySymbol == "EUR")
                   .Select(c => new RegionInfo(c.LCID).CurrencyEnglishName)
                   .FirstOrDefault();

which will return "Euro".

Note however that this gets the first RegionInfo that matches the currency symbol provided - not really an issue in this specific case, but could be if you are using the native currency name because the first country using the currency gets a match, which may have a different regional name for the currency than another country using the same currency (although probably not very likely).

adrianbanks