2015-10-06 85 views
0

這裏的代碼,這有助於找到組裝所需的文化線路:枚舉通過衛星組件支持的語言

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

但如何找到語言的哪些應用程序存在的附屬程序集,可以說,如果有3種語言支持,爲其創建了3個不同的文件夾,現在我希望支持其中的文件夾和語言。我從用戶可以選擇語言的地方下拉使用它,並且應該根據支持的附屬程序集動態加載下拉值。

+1

http://stackoverflow.com/questions/553244/programmatic-way-to-get-all-the-available-languages-in-satellite-assemblies的可能dublicate – hcp

回答

0

我有解決上述問題,以下解決方案:

這將是解決一個在下面的語句的基礎:
特定語言的每顆衛星組件名稱相同,但位於子文件夾以具體文化命名,例如fr或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))); 
}