为什么CultureInfo.DisplayName在
Sami
突然之间?我用它来显示一个国家名列表。也许不是个好主意,但它直到最近才起作用,我很确定它是用瑞典语写的(我想可能是英语)
MSDN说
此属性表示.NET框架版本中的本地化名称。例如,如果安装了.NET Framework英文版本,则属性返回“English(United States)”作为en-US区域性名称。如果安装了.NET Framework西班牙语版本,则无论系统设置为显示何种语言,区域性名称都将以西班牙语显示,并且en-US的属性将返回“Ingles(Estados Unidos)”。
但是我很确定我没有安装这个框架的Sami版本。
我的web配置有:
<globalization
culture="sv-SE"
uiCulture="sv-SE"/>
附加:代码
public static IEnumerable<KeyValuePair<string, string>> CountryList
{
get
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("sv-SE");
Thread.CurrentThread.CurrentUICulture = new
CultureInfo("sv-SE");
var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
/*Array.Sort(countries.Select(
x => Regex.Match(x.DisplayName, "\\(([\\w- ]+)\\)").ToString()).ToArray(),
countries);
*/
SortedDictionary<string, CultureInfo> d = new SortedDictionary<string, CultureInfo>();
foreach (CultureInfo cultureInfo in cultures)
{
string key = Regex.Match(cultureInfo.DisplayName, "\\(([\\w- ]+)\\)").ToString();
if (!d.ContainsKey(key))
d.Add(key, cultureInfo);
}
var countries = d
.Where(x => Regex.Match(x.Value.DisplayName, "\\([A-ZÃ
ÃÃ]").Success)
.Select(
x => new KeyValuePair<string, string>(
Regex.Match(x.Value.Name, "-(\\w+)").Groups[1].ToString(),
Regex.Match(x.Value.DisplayName, "\\(([\\w- ]+)\\)").Groups[1].ToString()
));
return countries;
}
}