Search code examples
c#wpfglobalizationsatellite-assembly

Enumerate the languages supported by satellite assemblies


Here is the line of code which help to find assembly for required culture:

Assembly.GetExecutingAssembly().GetSatelliteAssembly(new CultureInfo(cultureCode))

But how to find languages for which satellite assemblies exist for application, lets say if there are 3 language support for which 3 different folder created, now I want those folders and languages supported in it. I use this in drop down from where user can select language and drop down values should be dynamically loaded as per supported satellite assemblies.


Solution

  • I have solve above problem with following solution:

    This would be one of solution on basis of following statement:
    Each satellite assembly for a specific language is named the same but lies in a sub-folder named after the specific culture e.g. fr or fr-CA.

    public IEnumerable<CultureInfo> GetSupportedCulture()
    {
        //Get all culture 
        CultureInfo[] culture = CultureInfo.GetCultures(CultureTypes.AllCultures);
    
        //Find the location where application installed.
        string exeLocation = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));
    
        //Return all culture for which satellite folder found with culture code.
        return culture.Where(cultureInfo => Directory.Exists(Path.Combine(exeLocation, cultureInfo.Name)));
    }