Programmatic way to get all the available languages (in satellite assemblies)

前端 未结 7 518
青春惊慌失措
青春惊慌失措 2020-11-28 08:11

I\'m designing a multilingual application using .resx files.

I have a few files like GlobalStrings.resx, GlobalStrings.es.resx, GlobalStrings.en.resx, etc. When I wa

7条回答
  •  情深已故
    2020-11-28 08:28

    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 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)));
    }
    

提交回复
热议问题