我正在使用.resx文件设计多语言应用程序.
我有一些文件,如GlobalStrings.resx,GlobalStrings.es.resx,GlobalStrings.en.resx等.当我想使用它时,我只需要设置Thread.CurrentThread.CurrentCulture.
问题:我有一个包含所有可用语言的组合框,但我手动加载:
comboLanguage.Items.Add(CultureInfo.GetCultureInfo("en")); comboLanguage.Items.Add(CultureInfo.GetCultureInfo("es"));
我试过了
cmbLanguage.Items.AddRange(CultureInfo.GetCultures(CultureTypes.UserCustomCulture));
没有任何成功.还尝试了CultureTypes中的所有元素,但是我只获得了一个包含更多我不使用的语言的大列表,或者是一个空列表.
有没有办法只获得支持的语言?
您可以以编程方式列出应用程序中可用的文化
// Pass the class name of your resources as a parameter e.g. MyResources for MyResources.resx ResourceManager rm = new ResourceManager(typeof(MyResources)); CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); foreach (CultureInfo culture in cultures) { try { ResourceSet rs = rm.GetResourceSet(culture, true, false); // or ResourceSet rs = rm.GetResourceSet(new CultureInfo(culture.TwoLetterISOLanguageName), true, false); string isSupported = (rs == null) ? " is not supported" : " is supported"; Console.WriteLine(culture + isSupported); } catch (CultureNotFoundException exc) { Console.WriteLine(culture + " is not available on the machine or is an invalid culture identifier."); } }