Language Detection From Windows UI Language: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Description ==
== Description ==
Normally, NSIS chooses the default UI language based on the user's current locale settings. Most Windows applications choose their UI language using a different method; this script can be used to make NSIS installers use the same method as other applications.
In the '''past''' NSIS determined the default Installer UI language based on the user's current locale settings. Versions after 2.16 take the OS GUI language by default. The script below is to change to this behavior if you use an older NSIS version an can be used to make NSIS installers use the same method as other applications.


See this [http://forums.winamp.com/showthread.php?s=&threadid=228245 forum thread] for more details.
See this [http://forums.winamp.com/showthread.php?s=&threadid=228245 forum thread] for more details.
Line 71: Line 71:
!insertmacro SetUILanguage "un."
!insertmacro SetUILanguage "un."
</highlight-nsis>
</highlight-nsis>
[[Category:User Interface Functions]]

Latest revision as of 17:15, 8 December 2006

Description

In the past NSIS determined the default Installer UI language based on the user's current locale settings. Versions after 2.16 take the OS GUI language by default. The script below is to change to this behavior if you use an older NSIS version an can be used to make NSIS installers use the same method as other applications.

See this forum thread for more details.

Usage

Function .onInit
  Call SetUILanguage
FunctionEnd
 
Function un.onInit
  Call un.SetUILanguage
FunctionEnd

The Function

!define sysOSVERSIONINFO '(i, i, i, i, i, &t128) i'
!define sysGetVersionEx 'kernel32::GetVersionExA(i) i'
!define sysVER_PLATFORM_WIN32_NT 2
!macro SetUILanguage UN
Function ${UN}SetUILanguage
  Push $R0
  Push $R1
  Push $R2
  ; Call GetUserDefaultUILanguage (available on Windows Me, 2000 and later)
  ; $R0 = GetUserDefaultUILanguage()
  System::Call 'kernel32::GetUserDefaultUILanguage() i.r10'
  StrCmp $R0 "error" OldFashionedWay Finish
OldFashionedWay:
  ; GetUserDefaultUILanguage() doesn't exist, so root in the Registry
  ; First, check the Windows version
  ; $R0 = new OSVERSIONINFO(148, 0, 0, 0, 0, "")
  System::Call '*${sysOSVERSIONINFO}(148,0,0,0,0,"") .r10'
  ; GetVersionEx($R0)
  System::Call '${sysGetVersionEx}(r10)'
  ; $R1 = $R0->dwPlatformId
  System::Call "*$R0(i ., i ., i ., i ., i .r11)"
  ; delete $R0
  System::Free $R0
  IntCmp $R1 ${sysVER_PLATFORM_WIN32_NT} PlatformIsNT
  ; We're running on DOS-based Windows
  StrCpy $R0 "Control Panel\desktop\ResourceLocale"
  StrCpy $R1 ""
  GoTo GetLCIDFromHKCU
PlatformIsNT:
  ; We're running on Windows NT
  StrCpy $R0 ".DEFAULT\Control Panel\International"
  StrCpy $R1 "Locale"
	GoTo GetLCIDFromHKU
GetLCIDFromHKU:
  ReadRegStr $R2 HKU $R0 $R1
  GoTo GetLangIDFromLCID
GetLCIDFromHKCU:
  ReadRegStr $R2 HKCU $R0 $R1
GetLangIDFromLCID:
  StrCpy $R2 "0x$R2"
  IntOp $R0 $R2 & 0xffff
  ; Get just the primary LANGID (NSIS messes it up otherwise)
  IntOp $R0 $R0 & 0x3ff ; remove SUBLANGID
  IntOp $R0 $R0 | 0x400 ; add SUBLANG_DEFAULT
Finish:
  StrCpy $LANGUAGE $R0
  Pop $R2
  Pop $R1
  Pop $R0
FunctionEnd
!macroend
!insertmacro SetUILanguage ""
!insertmacro SetUILanguage "un."