简体   繁体   中英

Control of all installer elements' language in NSIS

I'm using nsis to create several installers. My installers contain EULA, custom forms (ie what to install). I would like to have one nsis script and be able to control different elements' text via language files. Elements can be: EULA text, next on buttons (ie 'next' in English vs. 'Proximo' in Spanish) and any other text displayed during installation. What is the correct way to implement this multilingual installer?

A basic example of how to use multiple languages:

Name "Test"
RequestExecutionLevel user
Outfile "Test.exe"


#Generate some license files on the fly
!tempfile LicFile1
!appendfile "${LicFile1}" "Hello from license 1."
!tempfile LicFile2
!appendfile "${LicFile2}" "Hello from license 2!"

LoadLanguageFile "${NSISDIR}\Contrib\Language files\Danish.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Swedish.nlf"

LicenseLangString licenseData ${LANG_DANISH} "${LicFile1}"
LicenseLangString licenseData ${LANG_SWEDISH} "${LicFile2}"

LicenseData $(licenseData)
LangString ^CancelBtn ${LANG_DANISH} "!lecnaC" ; Override built-in string from .nlf just for fun
LangString myCustomString ${LANG_DANISH} "Foo"
LangString myCustomString ${LANG_SWEDISH} "Bar"

Page License
Page InstFiles

!include LogicLib.nsh

Function .onInit
Push ""
Push ${LANG_DANISH}
Push "Danish"
Push ${LANG_SWEDISH}
Push "Bork bork"
Push A ; LangDLL: A means auto count languages
LangDLL::LangDialog "Installer Language" "Please select the language of the installer"
Pop $LANGUAGE
${IfThen} $LANGUAGE == "cancel" ${|} Abort  ${|}
FunctionEnd

Section "Dummy"
MessageBox MB_OK "$(myCustomString) and baz"
SectionEnd

!delfile "${LicFile1}"
!delfile "${LicFile2}"

Another example using MUI and "external" files for your custom strings:

Name "Test"
RequestExecutionLevel user
Outfile "Test.exe"


#Generate some language and license files for this example
!tempfile LicFile1
!appendfile "${LicFile1}" "Hello from license 1."
!tempfile LicFile2
!appendfile "${LicFile2}" "Hello from license 2!"
!tempfile CustomDanNsh
!appendfile "${CustomDanNsh}" '!insertmacro LANGFILE_EXT Danish$\n'
!appendfile "${CustomDanNsh}" '${LangFileString} myCustomString "red"$\n'
!tempfile CustomSweNsh
!appendfile "${CustomSweNsh}" '!insertmacro LANGFILE_EXT Swedish$\n'
!appendfile "${CustomSweNsh}" '${LangFileString} myCustomString "blue"$\n'

!include "MUI2.nsh"
!define MUI_LANGDLL_ALLLANGUAGES

!insertmacro MUI_PAGE_LICENSE "$(licenseData)"
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_LANGUAGE "Danish"
!insertmacro LANGFILE_INCLUDE "${CustomDanNsh}"
LicenseLangString licenseData 0 "${LicFile1}"
!insertmacro MUI_LANGUAGE "Swedish"
!insertmacro LANGFILE_INCLUDE "${CustomSweNsh}"
LicenseLangString licenseData 0 "${LicFile2}"


Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd

Section "Dummy"
MessageBox MB_OK "White or yellow on $(myCustomString)"
SectionEnd

!delfile "${CustomDanNsh}"
!delfile "${CustomSweNsh}"
!delfile "${LicFile1}"
!delfile "${LicFile2}"

NSIS has great support for this.

There is example with this feature called MultiLanguage which shows how to load separate languages into installer and use localized strings.

You can find it in NSIS\\Examples\\Modern UI\\MultiLanguage.nsi

(I am not sure I can paste whole script here, that may be against SO rules)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM