views:

477

answers:

4

My ASP.NET application is localized (by using resources) to many cultures. What I need is to find all these cultures (in runtime) and for example fill a DropDownList.

I have code which does that in windows applications - buids collection of available cultures by seeking satellite assemblies.

But what about web apps? It's possibe to find satellite assemblies? Or this can be done some other way?

Any suggestions?

Thanks

+3  A: 

Something like this should work for you ...

var ass = Assembly.GetExecutingAssembly();

foreach( var c in CultureInfo.GetCultures( 
  CultureTypes.SpecificCultures | 
  CultureTypes.NeutralCultures) ) 
{
  try 
  {
    var sat = ass.GetSatelliteAssembly( c );
    // Add to dropdown
   }
   catch( FileNotFoundException ) 
   {
   }
}
JP Alioto
This code works fine in windows-based apllications, but not in ASP.NET. Not sure, but I think GetSatelliteAssembly() is trying to load satellite assembly from a directory <culture-name>\<satellite_assembly_name>.dll. And ASP.NET apps use different locations.
Tadas
Interesting variable name
Jeremy Cron
+1 for your answer. But that is not exactly what I'm looking for.
Tadas
A: 

Hi,

I think your problem is to fill dropdownlist with culture.

For that you need to maintained one data file/ datatable where all supported culture is mentioned and then you can bind that with dropdownlist.

Please feel free to ask more?

Hemant Kothiyal
A: 

I have idea: iterate through all ..resx files in application's virtual directory and collect different culture names this way. I haven't tried this yet, but I think this should give me expected result.

Tadas
A: 

what culture is the name Jafar from?

tasha