Monday, August 19, 2013

NSIS customize files based on languages

 NSIS How to get user selected language without using registry function

This is an example based on my custom needed to rename config file for my application based on language selection by user during setup 

First onInit function you must pop $LANGUAGE variable on global stack as you can retrive it later.

Function .onInit
....

....
!insertmacro MUI_LANGDLL_DISPLAY
 Pop $LANGUAGE

FunctionEnd


Then on interested section you wite your custom language files (D_MyApp..... E_MyApp.... F_MyApp...)

Section "MainSection" SEC01
  SetOutPath "$INSTDIR"
  SetOverwrite try
  SetDetailsPrint none
  SetShellVarContext all
  File "D:\projects\xxxxx\MyApp_v32_09082013\D_MyApp.exe.config"
  File "D:\projects\xxxxx\MyApp_v32_09082013\E_MyApp.exe.config"
  File "D:\projects\xxxxx\MyApp_v32_09082013\F_MyApp.exe.config"


 Here you compare $LANGUAGE with
LCID value  (see http://www.science.co.il/Language/Locale-codes.asp  for reference)

If selected language match then rename file else continue if statement

  StrCmp $LANGUAGE '1031' customGerman noDE
  customGerman:
  Rename "$INSTDIR\D_MyApp.exe.config" "$INSTDIR\MyApp.exe.config"
  goto languageSettingsDone
 
  noDE:
  StrCmp $LANGUAGE '1033' customEnglish noEN
  customEnglish:
  Rename "$INSTDIR\E_MyApp.exe.config" "$INSTDIR\MyApp.exe.config"
  goto languageSettingsDone

  noEN:
  StrCmp $LANGUAGE '1036' customFrench noFR
  customFrench:
  Rename "$INSTDIR\F_MyApp.exe.config" "$INSTDIR\MyApp.exe.config"
  goto languageSettingsDone
 
  noFR:
  goto languageSettingsDone
 
  languageSettingsDone:
....

....
....

;Contiune with other files


If this short giude has been usefull for you please leave comment