Skip to content
⌘ NSIS Forum Archive

Set Language for default in Silent Mode custom

2 posts

meoit#

Set Language for default in Silent Mode custom

I need to show Language Dialog for user select, after that it show correct language which selected.

(I do not want to use /S for silent, I am trying to use -silent-install for my self)

But fail, it always show English.

This is code:

Unicode true
RequestExecutionLevel user
!include 'MUI2.nsh'
!include 'FileFunc.nsh'
!include 'x64.nsh'
!include 'WinVer.nsh'
Var /GLOBAL Var_Help
;--------------------------------
;General
  ;Name and file
  Name 'Test Help in Silent mode'
  OutFile 'Help.exe'
  ;Default installation folder
  InstallDir "$TEMP\Modern UI Test"
  ;Get installation folder from registry if available
  InstallDirRegKey HKCU "Software\HELP Installer" ""
;--------------------------------
;Interface Settings
;--------------------------------
;Pages
    !insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
    !insertmacro MUI_PAGE_COMPONENTS
    !insertmacro MUI_PAGE_DIRECTORY
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_UNPAGE_CONFIRM
    !insertmacro MUI_UNPAGE_INSTFILES
!define Show2Lang '!insertmacro Show2Lang'
!macro Show2Lang
    StrCpy $LANGUAGE ${LANG_THAI}
    !insertmacro MUI_LANGDLL_DISPLAY
!macroend
;--------------------------------
;Languages
    !insertmacro MUI_LANGUAGE "English"
    !insertmacro MUI_LANGUAGE "Thai"
    LangString LS_Help ${LANG_THAI} '้จะนำคุณไปสู่การยกเลิกการติด'
    LangString LS_Help ${LANG_ENGLISH} 'Help information'
Function .onInit
    ${GetParameters} $0
    ClearErrors
    ${GetOptions} `$0` '-help' $1
    ${IfNot} ${Errors}
        StrCpy $Var_Help 1
    ${Else}
        StrCpy $Var_Help 0
    ${EndIf}
    ;
    ${If} $Var_Help == 1
        ${Show2Lang}
        ${If} $LANGUAGE == 1054
            StrCpy $LANGUAGE ${LANG_THAI}
        ${Else}
            StrCpy $LANGUAGE ${LANG_ENGLISH}
        ${EndIf}
        MessageBox MB_OK|MB_USERICON|MB_TOPMOST '$(LS_Help)'
        Quit
    ${EndIf}
FunctionEnd
;--------------------------------
;Installer Sections
Section "Dummy Section" SecDummy
  SetOutPath "$INSTDIR"
  WriteRegStr HKCU "Software\HELP Installer" "" $INSTDIR
  WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
;--------------------------------
;Descriptions
  ;Language strings
  LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."
  ;Assign language strings to sections
  !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
    !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
  !insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
  Delete "$INSTDIR\Uninstall.exe"
  RMDir "$INSTDIR"
  DeleteRegKey /ifempty HKCU "Software\HELP Installer"
SectionEnd