views:

521

answers:

1

I've been doing localization for my WPF application by storing strings in .resx files. My default (english) string resource is strings.resx. For other languages are called strings.fr-FR.resx for French, strings.es-ES.resx for Spanish and so on.

This method of localization has been great as my app will automatically load up the right string when I set the Globalization region to a matching locale, and defaults to English when there isn't.

Is it possible at runtime to enumerate which languages are in my Assembly?

I could get around this and hard code in which languages are included, but this can change from build to build as a build server is putting together the language resx's and building dynamically.

A: 

I see two options, none of which is ideal...

  • Enumerate all known cultures (CultureInfo.GetCultures), and try to get a given ressource for this culture => simple but slow
  • Look for satellite assemblies in your application's directory : for each subdirectory, check if it's name corresponds to a culture name (CultureInfo.GetCultureInfo), and if it contains a .resources.dll file
Thomas Levesque