【问题标题】:Regional format and language in Windows Phone 10 UWP appWindows Phone 10 UWP 应用中的区域格式和语言
【发布时间】:2016-04-29 12:56:15
【问题描述】:

我正在开发本地化的 Windows (Phone) 10 UWP 应用。

我已经实现了对 2 种语言的支持:en-US 和 nl-NL(荷兰语-荷兰)。这很好用:当用户在手机设置中选择英语时,应用程序以英语启动,当用户在手机设置中选择荷兰语时,应用程序以荷兰语启动。

为了让它工作,我必须在 package.appxmanifest 中进行一些更改,因为我的语言资源位于不同的 DLL 中:

  <Resources>
    <Resource Language="nl-NL"/>
    <Resource Language="en-US"/>
  </Resources>

但我找不到任何方法从用户那里获取日期、时间和数字格式的区域格式。

当用户选择英语作为语言但选择荷兰语(荷兰)作为区域格式时,我的应用程序以两者开头 System.Globalization.CultureInfo.CurrentUICulture 和 System.Globalization.CultureInfo.CurrentCulture 设置为“en-US”,其中 System.Globalization.CultureInfo.CurrentCulture 应为“nl-NL”。

我一直在搜索所有文档,但找不到检索电话区域格式的方法(Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion 除外)。

有没有办法找回手机区域格式?

【问题讨论】:

标签: c# win-universal-app windows-10-mobile


【解决方案1】:

我只知道here提到的以下hack

 var systemLanguage = GlobalizationPreferences.Languages.First();
 var regionInfo = new RegionInfo(systemLanguage);
 var dtf = new DateTimeFormatter("longdate", new[] { regionInfo.TwoLetterISORegionName });
 var regionInfoName = dtf.ResolvedLanguage;
 var regionFormatCultureInfo = new CultureInfo(regionInfoName);

【讨论】:

    【解决方案2】:

    Peter Meinl 的回答有效,但有点令人困惑,因为您不需要 RegionInfo。

    Pedro Lamas 描述了使用“US”的 DateTimeFormatter 的 ResolvedLanguage 的 hack。

        DateTimeFormatter dtf = new DateTimeFormatter("longdate", new[] { "US" });
        string regionInfoName = dtf.ResolvedLanguage;
        CultureInfo regionFormatCultureInfo = new CultureInfo(regionInfoName);
    

    DateTimeFormatter 的 ResolvedLanguage 属性将包含手机的区域格式 ID,在本例中为“nl-NL”。

    请注意,您确实需要在 DateTimeFormatter 的构造函数中使用一种语言,只是 new DateTimeFormatter("longdate") 或 DateTimeFormatter.LongDate 不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多