Skip to content
⌘ NSIS Forum Archive

Multi-language Install Dir

13 posts

Ginndora#

Multi-language Install Dir

I am trying to update my NSIS installer (2.46) from a single language to a mutli-language (english, french, german) and I have just about everything nailed down but the install directory. The powers that be want the install directory to match the $(^Name), which I was able to get working passing in variables from my xml file:
;Name and file
Name $(Name)
LangString Name ${LANG_ENGLISH} "{#ProjectDisplayName}"
LangString Name ${LANG_FRENCH} "{#ProjectDisplayNameFR}"
LangString Name ${LANG_GERMAN} "{#ProjectDisplayNameDE}"
But I am having a hard time making my InstallDir get the correct name from the Langstring (this is what I have for a single language):
;Default installation folder
InstallDir "$PROGRAMFILES\Turbine\{#ProjectDisplayName}"
I am not sure what to replace my {#ProjectDisplayName} with or how to code it...I have tried using $(^Name), but that gives me only the default or EN version, it does not change to the other languages.

Any thoughts? Still learning the system so I am sure there is something obvious I am missing.

Thanks for any assistance!!
DO_Visser#
The example in the NSIS Help is very clear and should help you solve your problem instantly: http://nsis.sourceforge.net/Reference/LangString
Afrow UK#
If you need to use a language string in $INSTDIR, you will need to set its value manually with StrCpy after .onInit (rather than using InstallDir). I would set it in .onGUIInit (MUI_CUSTOMFUNCTION_GUIINIT for MUI) and in an empty Section on silent install (IsSilent or ${If} ${Silent}) because .onGUIInit isn't called for silent installs.

Stu
Ginndora#
So I am already using GUIINIT for setting my multilanguage images for the top banner and I figured I could add in setting the variable I want to use, but it does not seem to be working or I am doing something incorrectly:

!define MUI_CUSTOMFUNCTION_GUIINIT myGuiInit
Function myGUIInit
InitPluginsDir
${If} ${LANG_ENGLISH} = $Language
File "/oname=$PluginsDir\langspecifichdr.bmp" "{#TopBannerFile}"
StrCpy $DirClient "{#ProjectDisplayName}"
${EndIf}
${If} ${LANG_FRENCH} = $Language
File "/oname=$PluginsDir\langspecifichdr.bmp" "{#TopBannerFileFR}"
StrCpy $DirClient "{#ProjectDisplayNameFR}"
${EndIf}
${If} ${LANG_GERMAN} = $Language
File "/oname=$PluginsDir\langspecifichdr.bmp" "{#TopBannerFileDE}"
StrCpy $DirClient "{#ProjectDisplayNameDE}"
${EndIf}
SetBrandingImage /IMGID=1046 "$PluginsDir\langspecifichdr.bmp"
MessageBox MB_OK "$(^DirClient)"
FunctionEnd
Again, I am a newbie to this, so I am struggling a bit with understanding some of this. And I appreciate the help!!
Anders#
Before .onInit is executed something like this happens:

StrCpy $InstDir DirFromCommandlineIfAny
${If} $InstDir == ""
StrCpy $InstDir DirFromInstallDirRegKeyIfAny
${EndIf}
${If} $InstDir == ""
StrCpy $InstDir DirFromInstallDir
${EndIf}
and since the langstrings only reflect the chosen language after .onInit, using a langstring in InstallDir is not going to work because the langstring is resolved too early. You can use a variable in the InstallDir string or set $Instdir directly in .onInit with StrCpy...
Ginndora#
So I was able to successfully set the $Instdir in .onInit and when I launch the installer it works how I would assume, when the appropriate language is selected, the installation directory is localized. However....one of the reasons why I was attempting to set it to a variable like $DirClient is this example:
;Create shortcuts
CreateDirectory "$SMPROGRAMS\FOO\$StartMenuFolder\"
CreateShortCut "$SMPROGRAMS\FOO\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
CreateShortCut "$SMPROGRAMS\FOO\$StartMenuFolder\{#ProjectDisplayName}.lnk" "$INSTDIR\{#LauncherShortcutName}"
CreateShortCut "$DESKTOP\{#ProjectDisplayName}.lnk" "$INSTDIR\{#LauncherShortcutName}"
When I want to create the desktop shortcut and I want it localized, I figured a variable that was set during .onInit was the way to go so I could replace all the places I use {#ProjectDisplayName}. But it is not working...any thoughts??
Ginndora#
I can't thank you guys enough. I am now getting the response I need from the installer and it is localized the way I need it to be.

Again, I really appreciate the assistance.
Ginndora#
Multi Language Installer - Silent Installation

So, I have been requested to have our installer install silently from the command line. I know that when passing in /S it will install silently. But since I am running with a multi language installer that installs to a path based what language is chosen, the installer seems to get confused and installs the files to C:\ when using only /S. When I use /D with /S to pass in a directory, it installs to C:\. However, if I just use /D and I select the language from the language prompt, the directory will be the one I passed in using /D.

I am assuming this is because a language is not being passed in. How would I pass in a language choice so that I can have the installer install to the appropriate directory? Here is my .onInit so you can see what I am working with:
Function .onInit
!ifdef CREATE_UNINSTALLER
WriteUninstaller "$%TEMP%\uninstall.exe"
Quit ; just bail out quickly when running the "CREATE_UNINSTALLER" installer
!else
!insertmacro MUI_LANGDLL_DISPLAY
InitPluginsDir
!endif

${If} ${LANG_ENGLISH} = $Language
StrCpy $InstDir "$PROGRAMFILES\Turbine\{#ProjectDisplayName}"
${EndIf}
${If} ${LANG_FRENCH} = $Language
StrCpy $InstDir "$PROGRAMFILES\Turbine\{#ProjectDisplayNameFR}"
${EndIf}
${If} ${LANG_GERMAN} = $Language
StrCpy $InstDir "$PROGRAMFILES\Turbine\{#ProjectDisplayNameDE}"
${EndIf}
FunctionEnd
Again, thanks for any assistance that you may be able to offer.
Anders#
;DON'T USE: InstallDir
;DON'T USE: InstallDirRegKey

!include FileFunc.nsh
!include LogicLib.nsh
!include MUI2.nsh
!define MUI_CUSTOMFUNCTION_GUIINIT SetInstdirWithLangstring
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE German
!insertmacro MUI_LANGUAGE French
!insertmacro MUI_LANGUAGE English

LangString Bar ${LANG_ENGLISH} "Saint George's Cross"
LangString Bar ${LANG_FRENCH} "Drapeau Tricolore"
LangString Bar ${LANG_GERMAN} "Bundesflagge"

Function .onInit
${GetParameters} $1
${GetOptions} $1 "/LANGUAGE" $2
StrCpy $2 $2 "" 1 ; Remove = or : (/LANGUAGE=English)
${IfThen} $2 == "German" ${|} StrCpy $3 ${LANG_GERMAN} ${|}
${IfThen} $2 == "French" ${|} StrCpy $3 ${LANG_FRENCH} ${|}
${IfThen} $2 == "English" ${|} StrCpy $3 ${LANG_ENGLISH} ${|}
${If} $3 = 0 ; No language selected on the command line?
${IfNot} ${Silent}
!insertmacro MUI_LANGDLL_DISPLAY
${EndIf}
${Else}
StrCpy $Language $3
${EndIf}
FunctionEnd

Function SetInstdirWithLangstring
${If} $InstDir == ""
StrCpy $InstDir "$PROGRAMFILES\Foo\$(Bar)"
${EndIf}
FunctionEnd

Section -First
${If} ${Silent}
Call SetInstdirWithLangstring
${EndIf}
SectionEnd
..or something similar