【问题标题】:Enumerate the languages supported by satellite assemblies [duplicate]枚举附属程序集支持的语言[重复]
【发布时间】:2015-10-06 05:50:12
【问题描述】:
这是有助于找到所需文化的程序集的代码行:
Assembly.GetExecutingAssembly().GetSatelliteAssembly(new CultureInfo(cultureCode))
但是如何找到应用程序存在的附属程序集的语言,假设是否有 3 种语言支持创建了 3 个不同的文件夹,现在我想要其中支持的那些文件夹和语言。我在下拉列表中使用它,用户可以从中选择语言,下拉值应根据支持的附属程序集动态加载。
【问题讨论】:
标签:
c#
wpf
globalization
satellite-assembly
【解决方案1】:
我已经通过以下解决方案解决了上述问题:
这将是基于以下陈述的解决方案之一:
特定语言的每个附属程序集的名称相同,但位于以特定文化命名的子文件夹中,例如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)));
}