2016-04-29 45 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); 
相關問題