2016-04-29 46 views
2

我正在开发本地化的Windows(Phone)10 UWP应用程序。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这是不同的东西)。

有没有办法检索手机区域格式?

+0

http://stackoverflow.com/questions/13851854/how-to-find-the-default-dateformat-of-a-culture –

+0

@RahulJha,请在添加评论前阅读我的问题。您引用的线程不会告诉任何有关Windows Phone上的用户设置的内容。 –

回答

2

彼得的Meinl的答案的作品,但它是一个有点混乱,因为你并不需要的RegionInfo。

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

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

的DateTimeFormatter的ResolvedLanguage属性将包含电话的区域格式ID,在这种情况下,“NL-NL”。

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

2

我只知道下面的技巧中提到here

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); 
相关问题