2015-10-08 35 views
0

是否可以將LANGIDWin32_OperatingSystem映射到C#CultureInfo。或更具體的Locale財產Win32_OperatingSystem將LANGID從Win32_OperatingSystem映射到C#CultureInfo

這裏是描述由操作系統使用

Locale 
Data type: string 
Access type: Read-only 
Qualifiers: MappingStrings ("Win32API|National Language Support Functions|GetLocaleInfo|LOCALE_ILANGUAGE") 

語言標識符。語言 標識符是 國家/地區的標準國際數字縮寫。每種語言都有一個唯一的語言標識符 (LANGID),它由一個主要語言 標識符和第二語言標識符

我認爲,這將映射到的CultureInfo的LCID參數的一個16位的值,但那麼我在報告中得到了值409,並且它使CultureInfo.GetCultureInfo(lcid)拋出異常。

那麼得到CultureInfo(或其他任何能給我一個人名而不是語言代碼)的正確方法是什麼?

+1

* 409 *看起來太接近* 0x409 *(標準美式英語)是一個巧合。檢查你的代碼,一般來說,使用'GetCultureInfo(string)',因爲你從一個字符串開始。 – Amit

+0

@Amit:這是一個字符串是的。但它是「409」。但你是對的。我將它從一個十六進制字符串轉換爲一個整數。這工作。謝謝。你可以添加它作爲答案:'int lcid; (int.TryParse(currentValue,NumberStyles.HexNumber,NumberFormatInfo.InvariantInfo, out lcid)) currentValue = CultureInfo.GetCultureInfo(lcid).Name; } ' – jgauffin

回答

2

您需要解析字符串爲十六進制數:

int lcid; 

if (int.TryParse(currentValue, NumberStyles.HexNumber, 
    NumberFormatInfo.InvariantInfo, out lcid)) { 
    currentValue = CultureInfo.GetCultureInfo(lcid).Name; 
} 
+0

謝謝,幫助;) – jgauffin