我想根据用户的当前区域下载网站的内容。对于像我需要国家代码US,FR等等。如何获得呢?
我尝试了这些:
这总是显示美国。我认为它来自应用清单。
var region = RegionInfo.CurrentRegion;
Run Code Online (Sandbox Code Playgroud)
和这个:
var cultureName = new DateTimeFormatter("longdate", new[] { "US" }).ResolvedLanguage;
return new CultureInfo(cultureName);
Run Code Online (Sandbox Code Playgroud)
这可行。返回类似的内容en-US,我可以从中提取国家代码。但有时它可能只返回en不带国家代码的语言。
如何获取系统当前的两个字符的国家代码?谢谢。
要获取用户的家乡区域设置,我们可以使用 GlobalizationPreferences.HomeGeographicRegion属性。
// Obtain the user's home geographic region.
var region = Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion;
Run Code Online (Sandbox Code Playgroud)
通常在安装Windows时设置主区域,并且在
“设置”中可用。时间和语言?地区和语言?国家或地区。
Windows.Globalization还具有作为助手对象提供的GeographicRegion对象。它使应用程序可以检查有关特定区域的详细信息,例如其显示名称,本机名称和使用的货币。
// Get the user's geographic region and its two-letter identifier for this region.
var geographicRegion = new Windows.Globalization.GeographicRegion();
var code = geographicRegion.CodeTwoLetter;
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅管理语言和区域。
| 归档时间: |
|
| 查看次数: |
881 次 |
| 最近记录: |