我编写了一个NSIS脚本文件,该文件采用当前语言环境(在我们的示例中为“英语”)并生成安装程序。
在这里,我需要为此添加一些其他功能。
如果我要在此添加自己的页面,该怎么做?我可以在本地创建.nsh文件并使用它吗?
在这种情况下 ;页数 !insertmacro ...我们需要给出路径吗?
“语言文件”的缩写。例如,如果我想将自己的字符串添加到English.nsh文件,可以将其复制到本地文件夹吗?并在脚本中添加新字符串后如何使用?因为现在默认情况下,它是从C:\ Program Files \ NSIS \ Contrib \ Language文件中提取的。
以及如何在“ Function .onInit”中设置特定语言(与语言环境无关)
在我使用的基本代码段下面:
;NSIS Modern User Interface
;Multilingual Example Script
!pragma warning error all
;--------------------------------
;Include Modern UI
!include "MUI2.nsh"
;--------------------------------
;General
;Properly display all languages (Installer will not work on Windows 95, 98 or ME!)
Unicode true
;Name and file
Name "Locale Language"
OutFile "LocaleLanguage.exe"
;Default installation folder
InstallDir "$LOCALAPPDATA\LocaleLanguage"
;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\LocaleLanguage" ""
;Request application privileges for Windows Vista
RequestExecutionLevel user
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;Show all languages, despite user's codepage
!define MUI_LANGDLL_ALLLANGUAGES
;--------------------------------
;Language Selection Dialog Settings
;Remember the installer language
!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
!define MUI_LANGDLL_REGISTRY_KEY "Software\LocaleLanguage"
!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!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\License.txt"
!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 "French"
!insertmacro MUI_LANGUAGE "German"
!insertmacro MUI_LANGUAGE "Japanese"
!insertmacro MUI_LANGUAGE "Korean"
!insertmacro MUI_LANGUAGE "Italian"
!insertmacro MUI_LANGUAGE "Dutch"
!insertmacro MUI_LANGUAGE "Danish"
!insertmacro MUI_LANGUAGE "Greek"
!insertmacro MUI_LANGUAGE "Russian"
!insertmacro MUI_LANGUAGE "Portuguese"
;--------------------------------
;Reserve Files
;If you are using solid compression, files that are required before
;the actual installation should be stored first in the data block,
;because this will make your installer start faster.
!insertmacro MUI_RESERVEFILE_LANGDLL
;--------------------------------
;Installer Sections
Section "Dummy Section" SecDummy
SetOutPath "$INSTDIR"
;ADD YOUR OWN FILES HERE...
;Store installation folder
WriteRegStr HKCU "Software\Locale Language" "" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
;--------------------------------
;Installer Functions
Function .onInit
; !insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
;--------------------------------
;Descriptions
;USE A LANGUAGE STRING IF YOU WANT YOUR DESCRIPTIONS TO BE LANGAUGE SPECIFIC
;Assign descriptions to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} "A test section."
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
;ADD YOUR OWN FILES HERE...
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
DeleteRegKey /ifempty HKCU "Software\Locale Language"
SectionEnd
;--------------------------------
;Uninstaller Functions
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
FunctionEnd
更新:
下面是使用英语和瑞典语.nsh文件的更新代码。
!pragma warning error all
;--------------------------------
;Include Modern UI
!include "MUI2.nsh"
!include LogicLib.nsh
!include nsDialogs.nsh
;--------------------------------
;General
;Properly display all languages (Installer will not work on Windows 95, 98 or ME!)
Unicode true
;Name and file
Name "Locale Language"
OutFile "LocaleLanguage.exe"
;Default installation folder
InstallDir "$LOCALAPPDATA\LocaleLanguage"
;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\LocaleLanguage" ""
;Request application privileges for Windows Vista
RequestExecutionLevel user
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;Show all languages, despite user's codepage
!define MUI_LANGDLL_ALLLANGUAGES
;--------------------------------
;Language Selection Dialog Settings
;Remember the installer language
!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
!define MUI_LANGDLL_REGISTRY_KEY "Software\LocaleLanguage"
!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
;--------------------------------
;Pages
Page Custom mycustompage
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English" ; The first language is the default language
!insertmacro MUI_LANGUAGE "Swedish"
;--------------------------------
;Reserve Files
;If you are using solid compression, files that are required before
;the actual installation should be stored first in the data block,
;because this will make your installer start faster.
!insertmacro MUI_RESERVEFILE_LANGDLL
;Including the English and Swedish nsh files from the below path
!include "E:\prakash\LangTesting\LanguageFiles\English.nsh"
!include "E:\prakash\LangTesting\LanguageFiles\Swedish.nsh"
;--------------------------------
;Installer Sections
Section "Dummy Section" SecDummy
SetOutPath "$INSTDIR"
;ADD YOUR OWN FILES HERE...
;Store installation folder
WriteRegStr HKCU "Software\Locale Language" "" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
; To use the strings defined in English.nsh and Swedish.nsh files
!define MUI_PAGE_HEADER_TEXT "$(mypagetitle)"
!define MUI_PAGE_HEADER_SUBTEXT "$(mypagesubtitle)"
!define MUI_PAGE_DEFAULT_TEXT "$(defaulttext)"
var TextHandle
Function mycustompage
!insertmacro MUI_HEADER_TEXT $(mypagetitle) $(mypagesubtitle)
nsDialogs::Create 1018
Pop $0
${NSD_CreateText} 0 13u 100% 12u "$(defaulttext)"
Pop $TextHandle
nsDialogs::Show
FunctionEnd
;--------------------------------
;Installer Functions
Function .onInit
; !insertmacro MUI_LANGDLL_DISPLAY
;$LANGUAGE
System::Call 'KERNEL32::GetTickCount()i.r0' ; Get a "random" number
IntOp $0 $0 & 1
${If} $0 <> 0
StrCpy $Language ${LANG_SWEDISH} ; Force Swedish
${Else}
!insertmacro MUI_LANGDLL_DISPLAY ; Let the user choose a language
${EndIf}
FunctionEnd
;--------------------------------
;Descriptions
;USE A LANGUAGE STRING IF YOU WANT YOUR DESCRIPTIONS TO BE LANGAUGE SPECIFIC
;Assign descriptions to sections
;!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
; !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} "A test section."
;!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
**********
**English.nsh**
;Language: English (1033)
!insertmacro LANGFILE "English" = "English" =
LangString mypagetitle ${LANG_ENGLISH} "Hello"
LangString mypagesubtitle ${LANG_ENGLISH} "World"
***********
**Swedish.nsh**
;Language: Swedish (1053)
!insertmacro LANGFILE "Swedish" = "Svenska" =
LangString mypagetitle ${LANG_SWEDISH} "Bork"
LangString mypagesubtitle ${LANG_SWEDISH} "borkbork"
LangString defaulttext ${LANG_SWEDISH} "Skriva bork bork..."
LangString defaulttext ${LANG_ENGLISH} "Type something here..."
在这里,我在本地文件夹中创建了English.nsh和Sweedish.nsh文件,并包含了这些文件。然后定义那些字符串。当我运行时,它始终显示为“瑞典语”。它没有以英文显示。请让我知道这是正确的进行方式吗?以及是否需要任何更改?我在这里评论了“描述”部分,因为它引发了一些错误。为什么我们需要此“描述”部分?
答案 0 :(得分:0)
永远不要修改NSIS包含的.NSH文件,通常有一种方法可以覆盖特定内容。
您需要使用自定义页面插件中的one来创建自定义页面:
!include MUI2.nsh
Page Custom mycustompage
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
!insertmacro MUI_LANGUAGE Swedish
LangString ^InstallBtn ${LANG_ENGLISH} "Instaaaaall" ; Override default language string
LangString mypagetitle ${LANG_ENGLISH} "Hello"
LangString mypagesubtitle ${LANG_ENGLISH} "World"
LangString defaulttext ${LANG_ENGLISH} "Type something here..."
LangString mypagetitle ${LANG_SWEDISH} "Bork"
LangString mypagesubtitle ${LANG_SWEDISH} "borkbork"
LangString defaulttext ${LANG_SWEDISH} "Skriva bork bork..."
var TextHandle
!include LogicLib.nsh
!include nsDialogs.nsh
Function mycustompage
!insertmacro MUI_HEADER_TEXT $(mypagetitle) $(mypagesubtitle)
nsDialogs::Create 1018
Pop $0
${NSD_CreateText} 0 13u 100% 12u "$(defaulttext)"
Pop $TextHandle
nsDialogs::Show
FunctionEnd
Function .onInit
System::Call 'KERNEL32::GetTickCount()i.r0' ; Get a "random" number
IntOp $0 $0 & 1
${If} $0 <> 0
StrCpy $Language ${LANG_SWEDISH} ; Force Swedish
${Else}
!insertmacro MUI_LANGDLL_DISPLAY ; Let the user choose a language
${EndIf}
FunctionEnd
您可以通过将语言ID写入$Language
中的.onInit
来设置语言。您还可以使用一个语言选择对话框。 MUI自述文件显示了如何将LangStrings用于本节的说明...