Skip to content
⌘ NSIS Forum Archive

language settings on custom page

8 posts

Marcus1807#

language settings on custom page

Hi,

how can I change the language on a customPage?
I've coded the texts hard into the installer script.
But ho can I change the language with the language dialog?
Any ideas?

Thanks...
here is my code:

; Script generated by the HM NIS Edit Script Wizard.
!include WinMessages.nsh
!include LogicLib.nsh
; MUI 1.67 compatible ------
!include "MUI.nsh"
; Language Selection Dialog Settings
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
; Welcome page
 !insertmacro MUI_PAGE_WELCOME
;Custum Function
  Page custom showCheckSummary leaveCheckSummary
; License page
 !define MUI_LICENSEPAGE_CHECKBOX
 !insertmacro MUI_PAGE_LICENSE "Prototype.txt"
; Directory page
 !insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
 !insertmacro MUI_PAGE_INSTFILES
; Finish page
 !insertmacro MUI_PAGE_FINISH
; Uninstaller pages
 !insertmacro MUI_UNPAGE_INSTFILES
; Language files
 !insertmacro MUI_LANGUAGE "English"
 !insertmacro MUI_LANGUAGE "German"
; MUI end ------
Name "${PRODUCT_NAME}"
OutFile "Setup_ADEPAut.exe"
;VAR INI_VALUE
VAR ERROR_MESSAGE
Function showCheckSummary
 !insertmacro MUI_HEADER_TEXT "Environment errors" "The following environment checks failed."
 
 ;if no errors were found go to done else goto notEqual
 strcmp $9 "false" done notEqual
 notEqual:
  ;writeinistr "$PLUGINSDIR\checkSummary.ini" "FIELD 3" "State" "0"
  !insertmacro MUI_INSTALLOPTIONS_WRITE "checkSummary.ini" "FIELD 3" "State" "0"
  ;disable next button
  GetDlgItem $R0 $HWNDPARENT 1
  EnableWindow $R0 0
  ;writeinistr "$PLUGINSDIR\checkSummary.ini" "FIELD 2" "State" "$ERROR_MESSAGE"
  !insertmacro MUI_INSTALLOPTIONS_WRITE "checkSummary.ini" "FIELD 2" "State" "$ERROR_MESSAGE"
  InstallOptions::InitDialog /NOUNLOAD "$PLUGINSDIR\checkSummary.ini"
  
  ;ReadINIStr "$0" "$PLUGINSDIR\checkSummary.ini" "FIELD 2" "HWND"
  !insertmacro MUI_INSTALLOPTIONS_READ $0 "checkSummary.ini" 'Field 2' 'HWND'
  SetCtlColors $0 0x000000 0xFFFFFF
  InstallOptions::Show '$PLUGINSDIR\checkSummary.ini'
 done:
FunctionEnd
Function leaveCheckSummary
 ;readinistr $0 '$PLUGINSDIR\checkSummary.ini' 'Settings' 'State'
 !insertmacro MUI_INSTALLOPTIONS_READ $0 "checkSummary.ini" "Settings" "State"
 ${if} $0 == 1
 ${elseif} $0 == 3
   ;readinistr $3 '$PLUGINSDIR\checkSummary.ini' 'Field 3' 'State'
   !insertmacro MUI_INSTALLOPTIONS_READ $3 "checkSummary.ini" "FIELD 3" "State"
   ${if} $3 == 1
    GetDlgItem $R0 $HWNDPARENT 1
    EnableWindow $R0 1
   ${else}
    GetDlgItem $R0 $HWNDPARENT 1
    EnableWindow $R0 0
   ${endif}
  abort
 ${endif}
FunctionEnd
    
Function .onInit
 initpluginsdir
 gettempfilename $0
 rename $0 '$PLUGINSDIR\checksummary.ini'
 call WriteIni
  ;initialise $9 for error handling
  strcpy $9 "false"
 !insertmacro MUI_LANGDLL_DISPLAY
 ;Check Version-Number
 call CheckADVersion
 
 ;Read InstallDir
 call GetInstallDir
 StrCpy $INSTDIR "$R0"
 StrCpy $INSTDIR "..."
 
 ;Check Simatic Version-Number
 call CheckSimaticVersion
 ;CheckWindow
FunctionEnd
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\cmdhwconfig.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\cmdhwconfig.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd
Function GetInstallDir
 ClearErrors
 ReadRegStr $R0 HKLM "" "PATH"
 IfErrors error done
 error:
  strcpy $9 "true"
  strcpy $ERROR_MESSAGE "$ERROR_MESSAGEError while reading Install Directory from Registry.\r\n\r\n"
  goto done
 done:
FunctionEnd
Function CheckADVersion
 ClearErrors
 ReadRegStr $R1 HKLM "" "RELEASE"
 IfErrors error noError
 error:
  strcpy $9 "true"
  strcpy $ERROR_MESSAGE "$ERROR_MESSAGEError while reading Releasenumber of AD_Core_2006 from Registry.\r\n\r\n"
  goto goOn
 noError:
  strLen $2 ${PRODUCT_VERSION}
  strcpy $1 $R1 $2
  strCmp ${PRODUCT_VERSION} $1 goOn
    strcpy $9 "true"
    strcpy $ERROR_MESSAGE "$ERROR_MESSAGEWrong Releasenumber of AD_Core_2006 (Installed: $R1; Requested: ${PRODUCT_VERSION})\r\n\r\n"
    goto goOn
 goOn:
   goto done
 done:
FunctionEnd
Function CheckSimaticVersion
 ClearErrors
 ReadRegStr $R2 HKLM "" "RELEASE"
 IfErrors error noError
 error:
  strcpy $9 "true"
  strcpy $ERROR_MESSAGE "$ERROR_MESSAGEError while reading Releasenumber of  from Registry.\r\n\r\n"
  goto goOn
 noError:
  strLen $3 ${SIMATIC_VERSION}
  strcpy $4 $R2 $3
  strCmp ${SIMATIC_VERSION} $4 goOn
   strcpy $9 "true"
   strcpy $ERROR_MESSAGE "$ERROR_MESSAGEWrong Releasenumber of STEP7 (Installed: $R2; Requested: ${SIMATIC_VERSION})\r\n\r\n"
   goto goOn
 goOn:
   goto done
 done:
FunctionEnd 
Red Wine#
There is no need to post your entire script here.
All you need is read the manual at 4.9.15.2 LangString
and examine the included examples languages.nsi and MultiLanguage.nsi.
Marcus1807#
ok I still found the examples and looked at it.

so this has to work, or? :

...
; Language Selection Dialog Settings
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
; Language files
 !insertmacro MUI_LANGUAGE "German"
 !insertmacro MUI_LANGUAGE "English"
Function .onInit
 ; Select Language
 !insertmacro MUI_LANGDLL_DISPLAY
!if ${LANG_GERMAN}
   MessageBox MB_OK "DEUTSCH"
 !else if ${LANG_ENGLISH}
   MessageBox MB_OK "ENGLISCH"
 !Endif
FunctionEnd 
but it does not...why?
Thank you
Red Wine#
The !if statements you're using are suitable for the compiler not for installer, use LogicLib instead.
Marcus1807#
ok, now I tried this:

LangString Message ${LANG_ENGLISH} "Englisch"
LangString Message ${LANG_GERMAN} "Deutsch"
...
MessageBox MB_OK $(Message)

this does not work.
Then I tried it so:

${if} ${LANG_GERMAN}
MessageBox MB_OK "DEUTSCH"
${else} ${LANG_ENGLISH}
MessageBox MB_OK "ENGLISCH"
${endif}

what on hell is going wrong?
Marcus1807#
ok, now I have the mistake:

I had to move the instruction
call writeini
from .onInit to showChecksummary.
Red Wine#
Once you have defined all the desired multilingual text, (custom page's header and subheader text must be added into the page's create function) you have to replace all hard coded static text (labels, groupboxes, radios etc) with the corresponding multilingual message.


Be aware when you write to ini e.g.
type=groupbox
text=$(GroupBox_Txt)

The definition must already exist, so this can't be done into .onInit function.