程序化的方式来获得所有可用的语言(在附属程序集) [英] Programmatic way to get all the available languages (in satellite assemblies)
问题描述
我设计使用.resx文件多语言的应用程序。
I'm designing a multilingual application using .resx files.
我有这样GlobalStrings.resx,GlobalStrings.es.resx,GlobalStrings.en.resx等几个文件 当我想用这个,我只需要设置Thread.CurrentThread.CurrentCulture。
I have a few files like GlobalStrings.resx, GlobalStrings.es.resx, GlobalStrings.en.resx, etc. When I want to use this, I just need to set Thread.CurrentThread.CurrentCulture.
问题: 我有所有可用的语言组合框,但我手动加载这样的:
The problem: I have a combobox with all the available languages, but I'm loading this manually:
comboLanguage.Items.Add(CultureInfo.GetCultureInfo("en"));
comboLanguage.Items.Add(CultureInfo.GetCultureInfo("es"));
我试过用
cmbLanguage.Items.AddRange(CultureInfo.GetCultures(CultureTypes.UserCustomCulture));
没有任何成功。也试过在CultureTypes所有的元素,但我只得到一个大名单中有很多更多的语言说我不使用,或空列表。
without any success. Also tried with all the elements in CultureTypes, but I'm only getting a big list with a lot more languages that I'm not using, or an empty list.
有没有办法只得到支持的语言?
Is there any way to get only the supported languages?
推荐答案
使用什么符文格里姆斯塔说我结束了这一点:
Using what Rune Grimstad said I end up with this:
string executablePath = Path.GetDirectoryName(Application.ExecutablePath);
string[] directories = Directory.GetDirectories(executablePath);
foreach (string s in directories)
{
try
{
DirectoryInfo langDirectory = new DirectoryInfo(s);
cmbLanguage.Items.Add(CultureInfo.GetCultureInfo(langDirectory.Name));
}
catch (Exception)
{
}
}
或另一种方式
or another way
int pathLenght = executablePath.Length + 1;
foreach (string s in directories)
{
try
{
cmbLanguage.Items.Add(CultureInfo.GetCultureInfo(s.Remove(0, pathLenght)));
}
catch (Exception)
{
}
}
我仍然不认为这是个好主意......
I still don't think that this is a good idea ...
这篇关于程序化的方式来获得所有可用的语言(在附属程序集)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!