如何定制多种语言的NSIS安装程序屏幕
我正在使用NSIS创建安装程序。在创建安装程序时,我需要根据我的要求定制屏幕。我知道我们不应该修改NSIS包含的.NSH文件 所以,我的做法如下所示:但在这里,我需要为大约9种语言做这件事。有没有更好的方法将每种语言的单独文件分离并在此处使用? 以及如何将按钮和复选框作为自定义的一部分添加到许可协议屏幕如何定制多种语言的NSIS安装程序屏幕,nsis,Nsis,我正在使用NSIS创建安装程序。在创建安装程序时,我需要根据我的要求定制屏幕。我知道我们不应该修改NSIS包含的.NSH文件 所以,我的做法如下所示:但在这里,我需要为大约9种语言做这件事。有没有更好的方法将每种语言的单独文件分离并在此处使用? 以及如何将按钮和复选框作为自定义的一部分添加到许可协议屏幕 ;Include Modern UI !include "MUI2.nsh" RequestExecutionLevel admin ; Pages ;Page co
;Include Modern UI
!include "MUI2.nsh"
RequestExecutionLevel admin
; Pages
;Page components
;Page directory
;Page instfiles
;UninstPage uninstConfirm
;UninstPage instfiles
;Customizing the Welcome Text
!define MUI_TEXT_WELCOME_INFO_TEXT "The Setup Wizard will install Test installation on$\r$\n your computer. Click Next to continue or Cancel to exit the$\r$\n Setup Wizard."
!define MUI_WELCOMEFINISHPAGE_BITMAP "C:\Code\Code\NULLSOFT\src\Bitmaps\dlgbmp-for-test.bmp"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyWelcomeShowCallback
!insertmacro MUI_PAGE_WELCOME
;Customizing the License Page Text
!define MUI_TEXT_LICENSE_TITLE "End-User License Agreement"
!define MUI_TEXT_LICENSE_SUBTITLE "Please read the following license agreement carefully"
!define MUI_INNERTEXT_LICENSE_BOTTOM ""
!define MUI_INNERTEXT_LICENSE_TOP ""
!define MUI_PAGE_CUSTOMFUNCTION_LICENSESHOW MyLicenseShowCallback
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\test.rtf"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_LICENSE "${NSISDIR}\Docs\Modern UI\test.rtf"
!insertmacro MUI_UNPAGE_COMPONENTS
!insertmacro MUI_UNPAGE_DIRECTORY
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English" ; The first language is the default language
!insertmacro MUI_LANGUAGE "PortugueseBR"
;--------------------------------
;Installer Functions
Function .onInit
FunctionEnd
;--------------------------------
; The stuff to install
; WELCOME PAGE CALLING FUNCTION
Function MyWelcomeShowCallback
SendMessage $mui.WelcomePage.Text ${WM_SETTEXT} 0 "STR:$(MUI_TEXT_WELCOME_INFO_TEXT)"
FunctionEnd
Function MyLicenseShowCallback
SendMessage $mui.LicensePage.Text ${WM_SETTEXT} 0 "STR:$(MUI_TEXT_LICENSE_TITLE)"
FunctionEnd
使用两个单独的.nsh文件(CustomChinese.nsh和CustomEnglish.nsh)更新代码:
!include "MUI2.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!include "MyEnglish.nsh"
!include "MySwedish.nsh"
Section
DetailPrint $(myCustomString)
SectionEnd
!define MUI_TEXT_WELCOME_INFO_TITLE "Swedish bork bork"
!insertmacro MUI_LANGUAGE "Swedish"
LangString myCustomString 0 "Bork !?"
根据您的输入,我保留了!在单独的.nsh文件(CustomChinese.nsh和CustomEnglish.nsh)中定义每种语言的语句,然后将这些文件包括在my.nsi文件中
但它不允许同时包含两个.nsh文件(CustomChinese.nsh和CustomEnglish.nsh)和两个语言文件(!insertmacro MUI_language“English”和!insertmacro MUI_language“Chinese”)。所以,我只给出了一个文件。但是如何给出多个文件,以便根据区域设置选择适当的文件呢
以下是完整的代码:
Var IsOnLicensePage
Var PrintBtn
!include LogicLib.nsh
!include "MUI2.nsh"
Name "EMR 4.0"
OutFile "LocaleDlls.exe"
InstallDir $PROGRAMFILES\LocaleDlls
InstallDirRegKey HKLM "Software\NSIS_LocaleDlls" "Install_Dir"
; Request application privileges for Windows Vista
RequestExecutionLevel admin
;--------------------------------
; Pages
;Customizing the Welcome Text
!define MUI_WELCOMEFINISHPAGE_BITMAP "C:\NULLSOFT\src\Bitmaps\dlgbmp-for-test.bmp"
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyLicenseShowCallback
!define MUI_LICENSEPAGE_CHECKBOX ""
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\test\test.rtf"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_LICENSE "${NSISDIR}\Docs\test\test.rtf"
!insertmacro MUI_UNPAGE_DIRECTORY
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
; Below are the Custom Language Files
;!include "CustomEnglish.nsh"
!include "CustomChinese.nsh"
;--------------------------------
;Languages
;!insertmacro MUI_LANGUAGE "English" ; The first language is the default language
!insertmacro MUI_LANGUAGE "Chinese"
;Installer Functions
;--------------------------------
Function MyLicenseShowCallback
GetDlgItem $0 $hwndparent 2 ; Find cancel button so we can copy its size and y position.
System::Call *(i,i,i,i)p.r1
System::Call 'USER32::GetWindowRect(pr0,pr1)'
System::Call *$1(i.r2,i.r3,i.r4,i.r5)
IntOp $5 $5 - $3 ;height
IntOp $4 $4 - $2 ;width
System::Call 'USER32::ScreenToClient(p$hwndparent,pr1)'
System::Call *$1(i.r2,i.r3)
System::Free $1
IntOp $2 $4 / 5 ; Calculate x padding based on the width but you can put any value you want in $2
System::Call 'USER32::CreateWindowEx(i 0,t "Button",t "Print",i ${WS_CHILD}|${WS_VISIBLE}|${WS_TABSTOP},i r2,i r3,i r4,i r5,p $hwndparent,p 0x666,p 0,p 0)p.r0'
StrCpy $PrintBtn $0
SendMessage $hwndparent ${WM_GETFONT} 0 0 $1
SendMessage $0 ${WM_SETFONT} $1 1
GetFunctionAddress $0 onmybtnclick
ButtonEvent::AddEventHandler 0x666 $0
FunctionEnd
Function onmybtnclick
ExecShell "open" "$INSTDIR\test.rtf" "0"
FunctionEnd
; The stuff to install
Section "LocaleDlls (required)"
SectionIn RO
; Set output path to the installation directory. Here is the path C:\Program Files\LocaleDlls
SetOutPath $INSTDIR
; Give the File path
System::Call 'KERNEL32::AddDllDirectory(w "$INSTDIR")' ; Tell Windows we trust all .DLLs in this directory
;MessageBox MB_OK "Return value = $Language"
${If} $Language == 1033
MessageBox MB_OK "Current Locale is English... Loading English Files"
${ElseIf} $Language = 2052
MessageBox MB_OK "Current Locale is Chinese... Loading Chinese Files"
${EndIf}
; Do the install
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_DllTesting "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "DisplayName" "NSIS LocaleDlls"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
**Customtest.nsh**
!echo "NSIS Customtest"
!addincludedir "${NSISDIR}\Contrib\test 2"
;--------------------------------
;For Welcome Page
;For License Agreement Page
!define MUI_INNERTEXT_LICENSE_BOTTOM
!define MUI_INNERTEXT_LICENSE_TOP
!define MUI_INNERTEXT_LICENSE_BOTTOM_CHECKBOX
!define MUI_LICENSEPAGE_CHECKBOX
!insertmacro MUI_LANGUAGE "Chinese"
**CustomEnglish.nsh**
!echo "NSIS CustomEnglish"
!addincludedir "${NSISDIR}\Contrib\Modern UI 2"
;--------------------------------
;For Welcome Page
!define MUI_TEXT_WELCOME_INFO_TITLE "Welcome to the $(^NameDA) Setup Wizard"
!define MUI_TEXT_WELCOME_INFO_TEXT "The Setup Wizard will install EMR on$\r$\nyour computer. Click Next to continue or Cancel to exit the$\r$\nSetup Wizard."
;For License Agreement Page
!define MUI_TEXT_LICENSE_TITLE "End-User License Agreement"
!define MUI_TEXT_LICENSE_SUBTITLE "Please read the following license agreement carefully"
!define MUI_INNERTEXT_LICENSE_BOTTOM ""
!define MUI_INNERTEXT_LICENSE_TOP ""
!define MUI_INNERTEXT_LICENSE_BOTTOM_CHECKBOX ""
!define MUI_LICENSEPAGE_CHECKBOX ""
!define MUI_LICENSEPAGE_CHECKBOX_TEXT "I &agree to terms in the License Agreement"
!insertmacro MUI_LANGUAGE "English"
下面是更新后的代码片段!.nsh文件中的ifdef语句:
!include "MUI2.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!include "MyEnglish.nsh"
!include "MySwedish.nsh"
Section
DetailPrint $(myCustomString)
SectionEnd
!define MUI_TEXT_WELCOME_INFO_TITLE "Swedish bork bork"
!insertmacro MUI_LANGUAGE "Swedish"
LangString myCustomString 0 "Bork !?"
即使对我来说,这个样本也在起作用。但是,如果我在“MyEnglish.nsh”和“MySwedish.nsh”中都包含例如(MUI_CANCEL_MESSAGE“您确定要取消吗?”的MUI属性,则会显示编译器错误:!define:“MUI_CANCEL_MESSAGE”已定义
代码如下:
english.nsh
!define MUI_CANCEL_MESSAGE "Are you sure you want to cancel EMR?"
!insertmacro MUI_LANGUAGE "English"
MySetup.nsi:
!include "english.nsh"
!include "Swedish.nsh"
Function onAbort
${If} $PageId <> 0
${If} ${Cmd} ` MessageBox MB_YESNO "${MUI_CANCEL_MESSAGE}" IDYES `
;Call WelLeave
SendMessage $HWNDPARENT 0x408 -$PageId ""
${EndIf}
Abort
${EndIf}
FunctionEnd
有多种方法可以做到这一点 您可以手动覆盖每种语言的每个MUI字符串:
!include "MUI2.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!define MUI_TEXT_WELCOME_INFO_TITLE "English title goes here"
!insertmacro MUI_LANGUAGE "English"
!define MUI_TEXT_WELCOME_INFO_TITLE "Swedish bork bork"
!insertmacro MUI_LANGUAGE "Swedish"
如果希望每种语言有一个覆盖文件,可以将这些定义放在单独的文件中,并将其包含在内
另一种方法是将所有与语言相关的说明放在自定义语言文件中:
MySetup.nsi:
!include "MUI2.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!include "MyEnglish.nsh"
!include "MySwedish.nsh"
Section
DetailPrint $(myCustomString)
SectionEnd
!define MUI_TEXT_WELCOME_INFO_TITLE "Swedish bork bork"
!insertmacro MUI_LANGUAGE "Swedish"
LangString myCustomString 0 "Bork !?"
MySwedish.nsh:
!include "MUI2.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!include "MyEnglish.nsh"
!include "MySwedish.nsh"
Section
DetailPrint $(myCustomString)
SectionEnd
!define MUI_TEXT_WELCOME_INFO_TITLE "Swedish bork bork"
!insertmacro MUI_LANGUAGE "Swedish"
LangString myCustomString 0 "Bork !?"
不要在一个问题中问多个问题!看看我的例子,custom.nsh是
MUI_LANGUAGE
,而不是你的.nsit对我来说很好。我还创建了一个MyEnglish.nsh,其内容与MySwedish.nsh相同,但将“瑞典语”改为“英语”.Custom language字符串使用不同的语法。请看我的示例中的myCustomString。使用自定义langstring时,您不需要定义,请记住使用$(),而不是${}。