Archive: PreSelect a component by language


PreSelect a component by language
Hi together.

I've got a problem. I've have templates to install. Only one template should be selectable at once (problem solved). The other thing is that the installer should check which Language the system has and preselect the correct template for the user. I've startet with the following code:


var PreSelect

[... in the .oninit function ...]
StrCmp $LANGUAGE ${LANG_FRENCH} 0 +3
StrCpy $PreSelLang ${template_french}
goto PreSelectEnd

StrCmp $LANGUAGE ${LANG_GERMAN} 0 +3
StrCpy $PreSelLang ${template_german}
goto PreSelectEnd

StrCmp $LANGUAGE ${LANG_ITALIAN} 0 +3
StrCpy $PreSelLang ${template_italian}
goto PreSelectEnd

StrCmp $LANGUAGE ${LANG_SPANISH} 0 PreSelectEnd
StrCpy $PreSelLang ${template_spanish}
goto PreSelectEnd

StrCpy $PreSelLang ${template_english}
goto PreSelectEnd

PreSelectEnd:

[... the sections ...]
SectionGroup "Template language" templates
Section /o "English" templates_english
[stuff]
SectionEnd

Section /o "German" templates_german
[stuff]
SectionEnd

Section /o "French" templates_french
[stuff]
SectionEnd

Section /o "Italian" templates_italian
[stuff]
SectionEnd

Section /o "Spanish" templates_spanish
[stuff]
SectionEnd
SectionGroupEnd


.... and ...

Function .onSelChange
# EN, DE, IT, ES, FR
!insertmacro StartRadioButtons $PreSelLang
!insertmacro RadioButton ${templates_english}
!insertmacro RadioButton ${templates_french}
!insertmacro RadioButton ${templates_german}
!insertmacro RadioButton ${templates_italian}
!insertmacro RadioButton ${templates_spanish}
!insertmacro EndRadioButtons
FunctionEnd



What am I doing wrong? THe Buttons are RadioButtons but whatever language I have nothing is preselected. Any ideas? Thanks.

TIP:

Note that OS GUI language has nothing to do with the Targetcountry of your installer, make sure you do not confuse Language with Country, e.g. a person could have an Spanish OS GUI langiage but still have his country set to United States, since he/she lives there but prefers Spanish as OS language.


Hi onad,

thanks for the tip. I almost forgot to post the following lines which are also in my Installer:

System::Call "kernel32::GetUserDefaultLangID()i .r0"
StrCpy $LANGUAGE $0

So the Regional Settings should be used.

LoadLanguageFile "${NSISDIR}\Contrib\Language files\English.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\French.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\German.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Italian.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Spanish.nlf"

!include "LogicLib.nsh"
!include "Sections.nsh"

outfile 'test.exe'

Var PreSelLang

Page Components
Page InstFiles

SectionGroup /e "Template language" templates
Section /o "English" templates_english
; [stuff]
SectionEnd

Section /o "German" templates_german
; [stuff]
SectionEnd

Section /o "French" templates_french
; [stuff]
SectionEnd

Section /o "Italian" templates_italian
; [stuff]
SectionEnd

Section /o "Spanish" templates_spanish
; [stuff]
SectionEnd
SectionGroupEnd

Function .onInit
System::Call "kernel32::GetUserDefaultLangID()i .r0"
StrCpy $LANGUAGE $0

${if} $LANGUAGE == ${LANG_FRENCH}
!insertmacro SelectSection ${templates_french}
StrCpy $PreSelLang ${templates_french}

${elseif} $LANGUAGE == ${LANG_GERMAN}
!insertmacro SelectSection ${templates_german}
StrCpy $PreSelLang ${templates_german}

${elseif} $LANGUAGE == ${LANG_ITALIAN}
!insertmacro SelectSection ${templates_italian}
StrCpy $PreSelLang ${templates_italian}

${elseif} $LANGUAGE == ${LANG_SPANISH}
!insertmacro SelectSection ${templates_spanish}
StrCpy $PreSelLang ${templates_spanish}

${else}
!insertmacro SelectSection ${templates_english}
StrCpy $PreSelLang ${templates_english}
${endif}

MessageBox MB_OK "$$0 = $0 - $$LANGUAGE = $LANGUAGE - $$PreSelLang = $PreSelLang"
FunctionEnd

Function .onSelChange
# EN, DE, IT, ES, FR
!insertmacro StartRadioButtons $PreSelLang
!insertmacro RadioButton ${templates_english}
!insertmacro RadioButton ${templates_french}
!insertmacro RadioButton ${templates_german}
!insertmacro RadioButton ${templates_italian}
!insertmacro RadioButton ${templates_spanish}
!insertmacro EndRadioButtons
FunctionEnd

Thanks RedWine - this works. Now I have to solve another problem. My onInit function is before my sections. When I move my oninit function after the section the installers starts again and again and again (3 times before the first dialog appears). I have to investigate to solve this problem. Thanks again :)