3

无论如何要使用完整的显示名称创建cultureInfo 对象的实例:

CultureInfo userCulture = new CultureInfo("Japanese (Japan)");

或将完整的显示名称转换为文化代码:

toCultureCode("Japanese (Japan)"); 

会回来 "ja-JP"

4

2 回答 2

3

没有内置的方法可以通过它的英文名称来获取文化,所以你可以写一个:

public static CultureInfo getCultureByEnglishName(String englishName)
{
    // create an array of CultureInfo to hold all the cultures found, 
    // these include the users local culture, and all the
    // cultures installed with the .Net Framework
    CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
    // get culture by it's english name 
    var culture = cultures.FirstOrDefault(c => 
        c.EnglishName.Equals(englishName, StringComparison.InvariantCultureIgnoreCase));
    return culture;
}

演示

toCultureCodeToString:_

String name = "Japanese (Japan)";
CultureInfo japanCulture = getCultureByEnglishName(name);
Console.Write(japanCulture.ToString()); // -> "ja-JP"
于 2012-12-18T14:15:23.713 回答
2

您可以使用 Linq

using System.Linq;

CultureInfo culture = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(c => c.DisplayName == "Japanese (Japan)");
于 2012-12-18T14:19:41.097 回答