Somestimes our customers require us to package the software that way that it automatically sets the language according to the Windows UI Language.
Now the big question is, which is the best way to determine the language during a windows installer “transaction”?
Here you are:
dim dezUI,hexUI,language dezUI = GetUILanguage hexUI = hex(dezUI) do while len(hexUI) < 4 hexUI = "0" + hexUI loop If hexUI = "0404" Then language = "T_Chinese" ElseIf hexUI = "0804" Then language = "S_Chinese" Elseif right(hexUI,2) = "07" Then language = "german" Elseif right(hexUI,2) = "09" Then language = "english" Elseif right(hexUI,2) = "0C" Then language = "french" ElseIf hexUI = "0411" Then language = "Japanese" ElseIf hexUI = "0412" Then language = "Korean" ElseIf hexUI = "0416" Then language = "B_Portuguese" Elseif right(hexUI,2) = "0A" Then language = "spanish" Else language = "english" End If Session.Property("ONTX_LANGUAGE") = language
First we get the “decimal format” of the current UI language. The returned string is e.g 1033 which actually means “English – United States”.
Thats the first challenge: We usually only want to match a language and not a region at all. The next step is to convert that string into a hexdecimal value. And after that we have a value like this ‘409’. This value however must be 16Bit and therefore we add leading zero’s till we have a 4 digit hex value.
Now its quiet simple: the last 2 digits always(*) represent the language and the first 2 digits are for the region.
Examples:
- All english languages end with 09
- All french languages end with 0c
- All german languages end with 07
Bear in Mind: UI Language is a per user setting and you cannot therefore “ask” the operating system for it during a initial installation. this will run in system context and will always return english as language. you can however abuse the self repair or activesetup mechanism to run this script in per user context and then write the corresponding registry key/files.
(*) No rules without exceptions, you should anyway consult the following microsoft article:
Locale IDs Assigned by Microsoft: http://goo.gl/vjjst