当前文化名称为如果,否则或一个开关
本文关键字:开关 一个 文化名 如果 | 更新日期: 2023-09-27 18:10:03
我需要一个if或switch语句当前名称。我找不到解决办法。
这段代码不能运行。
if (Thread.CurrentThread.CurrentCulture == new CultureInfo("en"))
{
// EN (default)
}
if (Thread.CurrentThread.CurrentCulture == new CultureInfo("de"))
{
// DE
}
取决于你对"CultureName"的定义
// "ru-RU" on my workstation: Russian language (Russia dialect/subculture)
String name = Thread.CurrentThread.CurrentCulture.Name;
// "ru" - just Russian
String isoName = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
那么在你的例子中
// German, Germany (and not Austria)
if (Thread.CurrentThread.CurrentCulture.Name.Equals("de-DE")) {
...
}
else if (Thread.CurrentThread.CurrentCulture.Name.Equals("de-AT")) {
// German, but Austrian subculture
...
}
或
// German, any subculture, dialect ect.
if (Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Equals("de")) {
...
}